Search results

Prevent nullable input in NumericTextBox in ASP.NET Core NumericTextBox control

22 Jul 2021 / 1 minute to read

By default, the value of the NumericTextBox sets to null. In some applications, the value of the NumericTextBox should not be null at any instance. In such cases, following sample can be used to prevent nullable input in NumericTextBox.

tagHelper
nullableInput.cs
Copied to clipboard
<div id='container'>
    <div class='wrap'>
        <ejs-numerictextbox id="numeric" value="10" placeholder="NumericTextBox" floatLabelType="Always" created="onCreate" blur="onBlur"></ejs-numerictextbox>
    </div>
</div>

<script>
    function onCreate(args) {
        if (this.value == null) {
            this.value = 0;
        }
    }
    function onBlur(args) {
        if (args.value == null) {
            numeric.value = 0;
        }
    }
</script>
Copied to clipboard
public ActionResult nullableInput()
{
    return View();
}

Output be like the below.

NumericTextBox Sample