We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Reset angular numeric TextBox to default value on invalid content

Hi I am trying to reset a numeric textbox back to the original value when invalid input is detected (deleting all the contents of the field causes the field to remain empty instead of reverting back to the default)
The main problem is that it is not re-rendering when the $scope.intervallength value changes is there a way of resetting the textbox when the contents are not a number?


    <input id="IntervalLengthSpinner" type="text" ej-numerictextbox e-value="intervalLength" e-focusout="focusOut" e-minvalue="1" e-maxvalue="10000" />

Inside the controller I am using the following:


   $scope.intervalLength = 1;

            $scope.focusOut = function (args) {
                if (!angular.isNumber(args.value)) {

                  console.log("invalid entered");
                   $scope.$apply(function () {
                        $scope.intervalLength = 1;
                    });
                
                    //$scope.intervalLength = 1;
                    // var y = $("#" + args.model.name + "~ .e-select").find(".e-spin.e-spin-up");
                    //   y[0].click();
                    //var u = y.find(".e-spin.e-spin-up");
                    //$("#" + args.model.name[0]).find("e-spin e-spin-up")[0].click();
                    //var t = $("#" + args.model.name);
                    //$scope.$apply(function() {
                    //    $("#" + args.model.name).prop({ "aria-valuenow": 1 });
                    //});
                   //args.value=$scope.intervalLength;

                    // $scope.$apply();
                }
                else {
                    $scope.intervalLength = args.value;
                    console.log("valid");
                    console.log($scope.intervalLength);
                }
            };

1 Reply

SN Sasikala Nagarajan Syncfusion Team June 17, 2015 03:54 AM UTC

Hi Robert,

Thanks for using Syncfusion products,

We have analyzed your query. We have prepared the simple sample based on your requirement.

Please get the sample from below location

Sample

In this sample, in numeric text box change event, we have validated the numeric text box value and sets to default the value to textboxif the numeric text box value is not a number.

Please refer the below code snippet

$scope.valueChange = function(args) {

if (!angular.isNumber(args.value))

{

s=$("#numeric").ejNumericTextbox('instance');


$scope.$apply($scope.nvalue=""); // bind the value to empty before bind the same value to model.

$scope.$apply($scope.nvalue=1);

}

}



Please check with given sample andlet us know if you further quieries,

Regards,

Sasikala Nagarajan


Loader.
Live Chat Icon For mobile
Up arrow icon