Format field

Hi support, in my form i've a numeric textbox and i need to accept and show the number format as 001. The numeric text box show 1 ( correctly it's a numeric textbox).
It's possible to accept alse the format withe the leading zeroes ?

Thanks in advance
Stefano Capobianco

5 Replies

AB Ashokkumar Balasubramanian Syncfusion Team November 27, 2017 12:31 PM UTC

Hi Stefano, 
 
Yes its possible, we can format the Numeric Textboxes values with leading zeroes using Numeric Textbox positivePattern property. Please check the below code block. 
   
[CSHTML] 
 
<ej-numeric-text-box id="numeric" value="0" min-value="0" max-value="999" create="valueFormatting" focus-out="valueFormatting" /> 
 
[Script] 
 
function valueFormatting (args) { 
                if (args.model.value < 100) { 
                  args.model.value < 10 ? this.option("positivePattern", "00n"):this.option("positivePattern", "0n"); 
                } 
                else { 
                    this.option("positivePattern", "n"); 
                } 
      } 
 
To know more details about positivePattern property, please check the below API document. 
 
 
Please let us know, if the provided information’s are helpful to achieve this requirement or not. 
 
Regards, 
Ashokkumar B.  



SC Stefano Capobianco November 27, 2017 04:09 PM UTC

Hi the solution work very well inside the html form but when i see the value inside the model, the field value is n and not 00n or 0nn. It's possible to have the field value like i need ?

Thanks in advance
Stefano


AB Ashokkumar Balasubramanian Syncfusion Team November 28, 2017 12:58 PM UTC

Hi Stefano, 
 
Thanks for your update. 
 
We have checked your query (“Get the showcased Textbox value to controller”). In our Numeric Textboxes only hold the valid numeric values on Models, so we are unable to get the showcased number format value in controller part with the help of previous update. For this scenario, we have suggest to change the element value (as like textbox value) to resolved this problem, please check the below modified code block.  
 
[Script] 
 
function valueFormatting(args) { 
            if (args.model.value < 100) { 
                args.model.value < 10 ? this.option("positivePattern", "00n") : this.option("positivePattern", "0n"); 
            } 
            else { 
                this.option("positivePattern", "n"); 
            } 
            this.element.val(this._textBox.value); 
        } 
 
Please let us know, if you have any concern on this. 
 
Regards, 
Ashokkumar B. 



SC Stefano Capobianco November 28, 2017 03:08 PM UTC

Thanks for your answer. i've switched to the input text box with a regex rule validation.

Stefano


AB Ashokkumar Balasubramanian Syncfusion Team November 29, 2017 10:31 AM UTC

Hi Stefano, 
 
Sorry for the inconvenience. 
 
Please let me know, if you are facing any difficulties to use our Numeric Textbox component in validation and customization scenarios. 
 
Regards, 
Ashokkumar B.  


Loader.
Up arrow icon