AngularJS Validation on <select> with a prompt option

前端 未结 9 2122
挽巷
挽巷 2021-02-05 11:17

I have the following code for a select drop down input that is styled in Bootstrap.


    
    
    

in Controller:

$scope.businessprocess = "A" ;

or "C","Q",whatever you want, so the select will always have value. i think you don't need "required" here in select.

If you don't want an init a value. also do some extra effect when user don't select it.


then write the directive:

model.directive("myRequired", function() {
    return {
        restrict: 'AE',
        scope: {},
        require: 'ngModel',
        link: function(scope, iElement, iAttrs) {
                if(iElement.val() == ""){
                    //do something
                    return;
                } else {
                    //do other things
                }
            });
        }
    };
});

提交回复
热议问题