Remove all formatting from ejs-numerictextbox

Hi, how can i remove any kind of automatic formatting from 'ejs-numerictextbox' control? It must show what is entered. The number of decimals can vary, it is not fixed.

Best regards,
Massimo


9 Replies

UD UdhayaKumar Duraisamy Syncfusion Team September 26, 2022 04:09 PM UTC

Hi Massimo,


We suggest setting the format property as per your requirement to avoid the auto round of the value entered by the user in the Numeric TextBox component. Please refer to the below documentation for more details.


<ejs-numerictextbox id="numeric" value="10" format="n5" ></ejs-numerictextbox>


Documentation : https://ej2.syncfusion.com/aspnetcore/documentation/numerictextbox/formats


API link : https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Inputs.NumericTextBox.html#Syncfusion_EJ2_Inputs_NumericTextBox_Format


Supported Format String : https://ej2.syncfusion.com/aspnetcore/documentation/common/internationalization#supported-format-string


Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/CoreNTB-614898080


Kindly try the above suggestion and let us know if this meets your requirement. If we misunderstood the requirement, we request you to provide additional details about the requirement as mentioned below. This will help us validate the requirement further and provide you with a better solution.

  1. Exact Requirement details.
  2. Requirement use case scenario.


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Udhaya Kumar D




MA Massimo September 28, 2022 07:27 AM UTC

Thank you for your response.


My problem is that the value should not be formatted at all, putting "n5" even the value 0.5 is displayed at 0.50000.

The same field can have values with different decimals, but this should not be formatted:

1.2 => 1.2

0.45 => 0.45

100 => 100

0.362 => 0.362

without additional decimals.


Regards,
Massimo




UD UdhayaKumar Duraisamy Syncfusion Team September 29, 2022 04:07 PM UTC

Hi Massimo,


We are validating the requirement. We will update the further details in two business days (3rd October 2022).


Regards,

Udhaya Kumar D



UD UdhayaKumar Duraisamy Syncfusion Team October 3, 2022 01:25 PM UTC

Hi Massimo,


Sorry for the inconvenience.


We suggest setting the format property as “n” for your requirement. While setting the format property as n, the Numeric TextBox will accept the user input as it is and it will not format the input value.


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Udhaya Kumar D




MA Massimo October 3, 2022 11:30 PM UTC

Sorry, but it still doesn't work, if I enter the value 0.00069 it is displayed as 0.001, instead of 0.00069:


<ejs-numerictextbox id="numericTextBoxTest" format="n">

</ejs-numerictextbox>


Regards,

Massimo




UD UdhayaKumar Duraisamy Syncfusion Team October 5, 2022 12:00 AM UTC

Hi Massimo,


We are validating the requirement. We will update the further details in two business days (6th October 2022).


Regards,

Udhaya Kumar D



UD UdhayaKumar Duraisamy Syncfusion Team October 7, 2022 12:55 PM UTC

Hi Massimo,


We can achieve the requested requirement by overriding the source code. W have prepared a sample and shared it below for reference.


@{

    ViewData["Title"] = "Home Page";

}

 

<ejs-numerictextbox id="numeric"format="n"></ejs-numerictextbox>

 

<script>

ej.inputs.NumericTextBox.prototype.modifyText = function () {

        if (this.value || this.value === 0) {

            var value = this.formatNumber();

            var elementValue = value;

            this.setElementValue(elementValue);

Object(_ej2_base__WEBPACK_IMPORTED_MODULE_0__["attributes"])(this.element, { 'aria-valuenow': value });

            this.hiddenInput.value = this.value.toString();

            if (this.value !== null && this.serverDecimalSeparator) {

                this.hiddenInput.value = this.hiddenInput.value.replace('.', this.serverDecimalSeparator);

            }

        }

        else {

            this.setElementValue('');

            this.element.removeAttribute('aria-valuenow');

            this.hiddenInput.value = null;

        }

    }

</script>


Sample  : https://www.syncfusion.com/downloads/support/directtrac/general/ze/CoreNTB1084524682


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Udhaya Kumar D



MA Massimo October 17, 2022 07:36 PM UTC

Thank you, sorry for the delay.

However, I have an error on the reference "_ej2_base__WEBPACK_IMPORTED_MODULE_0__" (is not defined).

Do I need to add any particular reference?

Best regards,
Massimo




UD UdhayaKumar Duraisamy Syncfusion Team October 20, 2022 07:22 AM UTC

Hi Massimo,


We were able to reproduce your reported issue. The error happened due to using webpack to add the attribute. Now, modified it by adding attributes using the base method.

We suggest referring to the below code and sample to solve your problem.


Index.cshtml

<script>

ej.inputs.NumericTextBox.prototype.modifyText = function () {

        if (this.value || this.value === 0) {

            var value = this.formatNumber();

            var elementValue = value;

            this.setElementValue(elementValue);

           ej.base.attributes(this.element, { 'aria-valuenow': value  });

            this.hiddenInput.value = this.value.toString();

            if (this.value !== null && this.serverDecimalSeparator) {

                this.hiddenInput.value = this.hiddenInput.value.replace('.', this.serverDecimalSeparator);

            }

        }

        else {

            this.setElementValue('');

            this.element.removeAttribute('aria-valuenow');

            this.hiddenInput.value = null;

        }

    }

</script>


Sample Link:  

https://www.syncfusion.com/downloads/support/directtrac/general/ze/CoreNTB1084524682


Regards,

Udhaya Kumar D


Loader.
Up arrow icon