Hello, looking at this example I find that it works different on my angular app. Input field does not accept/display "0" value.
Inputmask for integers on angular does not display "0"
Answers approved by surveyjs Support
Hello Saulius,
Please accept my apologies for the delayed reply. I researched this issue and it appears, that the question value is reset to an empty string (""
) because of the following code within the onblur
event of a custom Inputmask widget (source code for Inputmask.js)
JavaScriptel.onblur = function () {
if (!el.inputmask) return;
if (surveyElement.value === el.inputmask.getemptymask()) {
surveyElement.value = "";
}
};
The el.inputmask.getemptymask()
function returns "0"
, which equals to the current sureyElement.value
property value.Therefore, a value is reset to ""
.
As it's mentioned in the Inputmask documentation (getemptymask command), the getemptymask
returns the default (empty) mask value. To ensure that a 0
value is correctly preserved in survey results, I would suggest that you customize the default (empty) mask value for the Inputmask widget. For instance, try the '_'
mask.
JavaScriptconst getEmptyMask = () => {
return "_";
};
el.onblur = function () {
if (!el.inputmask) return;
if (surveyElement.value === getEmptyMask()) {
surveyElement.value = "";
}
};
I created the following demo for your reference: View Demo. Pay special attention to the inputmask.js
file. It registers a custom Inputmask widget and overrides the onblur
event to register a custom empty mask. Now, the 0
value is correctly preserved in survey results.
I hope this example helps. Please let me know if you have any further questions.
Hi,
Thank you for reporting this issue. We may need additional time to research it. I'll update this thread as soon as I have any news to share.