How to use
- Save the code below as a new JS-file wherever you keep your custom controls. Don't know where to put it? Create a subfolder in your app called
control
(next toview
andcontroller
) and refer to the UI5 walkthrough tutorial for further information. - Include it in your view as
StepInputCustom
(see tutorial for details). - Use
StepInputCustom
instead ofsap.m.StepInput
to enable empty values.
The Code
Replace your.namespace
with the desired namespace - e.g. the namespace of your app if you lean on the walkthrough tutorial above.
The custom control overrides all methods, that sanitize values and adds a check for empty values to each of them. Non-empty values are simply passed on to the regular sap.m.StepInput
, so there is no change in logic.
(function () { "use strict"; /** * A custom version of sap.m.StepInput, that can be empty. */ sap.m.StepInput.extend("your.namespace.StepInputCustom", { renderer: {}, _getDefaultValue : function (value, max, min) { if (value === "" || value === undefined || value === null) { return ""; } return sap.m.StepInput.prototype._getDefaultValue.call(this, value, max, min); }, _getFormatedValue : function (vValue) { if (vValue === "" || vValue === undefined || vValue === null) { return ""; } return sap.m.StepInput.prototype._getFormatedValue.call(this, vValue); }, setValue : function (oValue) { if (oValue === "" || oValue === undefined || oValue === null) { this._getInput().setValue(""); this._disableButtons(0, this.getMax(), this.getMin()); return this.setProperty("value", "", true); } return sap.m.StepInput.prototype.setValue.call(this, oValue); }, validateProperty : function(sPropertyName, oValue) { if (sPropertyName === "value" && (oValue === null || oValue === "" || oValue === undefined)) { return ""; } return sap.m.StepInput.prototype.validateProperty.call(this, sPropertyName, oValue); } }); })();