Prevent nullable input in NumericTextBox
7 Jun 20241 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.
@Html.EJS().NumericTextBox("numeric").Created("onCreate").Blur("onBlur").Render()
<script>
function onCreate(args) {
if (this.value == null) {
this.value = 0;
}
}
function onBlur(args) {
if (args.value == null) {
numeric.value = 0;
}
}
</script>
public ActionResult nullableInput()
{
return View();
}
Output be like the below.