Question T13474
Visible to All Users

Inputmask and typescript, I can not run it / It is not working for numbers the "," and "." in the SurveyJS

created 2 years ago

Hello, I need support with the Inputmask and the decimals numbers.
I am using in my project React, Typescript, NextJs and SurveyJs.
When I am trying to follow the steps that your mention in your documentation it is not working at all and it is asking me some definitions.

I tried to install the options that the error showed me and it is not working. I can not find how to resolve this.

I was reading in one of the issues that your solved before about put a "," or a "." between the numbers and it said that you solved it but for me it is also not working.
I have a questionnaire where I need to insert a number with decimals and the survey do not let me. It only allows to save enter whole numbers and if I add a comma or a dot it throw me an error and do not let me save.

So, I decided to install the inputmask but I can not do that this work neither.

I attached screenshots with the error in the installation of Inputmask and the screenshots with the input number error comma and dot, also the success when you only enter the entire number.

I hope you can help me.
Thanks.
Eliana

Answers approved by surveyjs Support

created 2 years ago

Hello Eliana,
It should work out of the box. Here is the example. You can see results in console.
It shows 1.2 on entering "1.2" and "1,2" for me in Chrome.

Thank you,
Andrew
SurveyJS Team

    Show previous comments (5)

      Hello Eliana,
      Thank you for the update. I tested an example shared by Andrew (https://plnkr.co/edit/A7rTkq2C5kuVKR2E)) with Chrome and Firefox browsers.

      Regardless of a browser, an input field accepts values with a dot . decimal separator only.
      If you wish to use a comma , as a decimal separator, you can modify the numericRadixPoint property of an Inputmask widget. Please test this Example.

      JavaScript
      Survey.CustomWidgetCollection.Instance.getCustomWidgetByName("maskedit").widgetJson.numericRadixPoint = ",";

      Let us know if you have further questions.

        Hi Jane, Thanks for the answer, Well, we have a lot of problems with the dots and the commas.
        I tried to use Inputmask but I never could, I am using Typescript and I think it is something there that is not well for me.
        I also tried with the example that Andrew sent to me last week (with the function) but also I have problems with typescript.
        Then I decided to try the input validation with regex:

        Code
        "validators": [ { "type": "regex", "regex": "^\\d+(?:[.]\\d+)?$", "text": "Please check your input format. Please use the period (.) as a separator in your input." } ]

        The example in your page:
        https://surveyjs.io/form-library/examples/javascript-form-validation/reactjs#content-code

        So now I am using the regex and it is working ok, I only admit in the input the dot and I made others with only two decimals and with percentage. They work very well.

        In part it solves my problem, but if I use this REGEX I can not use inputType: number, so the input is a text (string) and I have to convert all my numbers again in numbers later.

        Also now, I am saving every time the question is validated like this:

        Code
        // Autosaving survey results with check if there is an error on validation survey?.onValidateQuestion.add(function (surveyModel, options) { var errorNull = options.error; if (surveyModel && errorNull == null) { const allAnswers = surveyModel.data; const filteredAnswers = updateObjectValues(questionNamesCurrentSection, allAnswers); postQuestionnaireAnswers(filteredAnswers); } });

        and it is working perfectly but only in simple questions and in panel questions, NOT in matrix, the validation there only appear the input in red, without a popup error message and the data save without the verification.
        So I should avoid the matrix.

        The big thing that I would like to solve now is the problem with the string instead numbers.

        I really appreciate all the help that you guys gave me, maybe all this messages are useful for someone else.

        Thanks

          Hello Eliana,
          I appreciate your descriptive explanation. Instead of saving answers within the onValidateQuestion event, I may suggest that you do so on survey completion. Handle the survey.onComplete event, obtain user answers from survey.data and convert answers to a required format. An example on how to modify survey results is available on our website: Modify Survey Results.

          As for validating matrices: there is a special survey.onMatrixCellValidate event which allows you to validate answers within matrix cells. The options.error parameter allows you to define an error text. The text appears when a user hovers a cell with a mouse pointer.

          Should you have any questions or require further assistance, please feel free to contact us at your convenience.

          Thanks

          P.S. We hope you enjoyed the level of service you received. If so, we would love if you could leave your feedback on SurveyJS page at g2.com. As we’re building our business, every review helps build credibility for future customers and your feedback would be greatly appreciated.