Angularjs Select Doesn't Error When Model Value Not In Options December 12, 2023 Post a Comment Angular 1.4.8. I have this markup for 2-letter US state codes: Solution 1: One thing you can do to trigger errors on the ngModel directive is to add a custom validator to the ngModel's $validators. The ngModel's value is passed through the $validators whenever it changes, and an error is raised if the validator returns false. An example implementation is to add a custom directive to the model's element, and define the validator inside that directive: Baca JugaIndexof Deletes The Wrong Item In AngularjsHow To Define A Kendo Grid Column Filter Between Two Dates?How To Bind An Td Contenteditable Value To Ng-modelHere's a plunkr with a working example: http://plnkr.co/edit/m6OygVR2GyMOXTTVTuhf?p=preview// markup <select name="licenseState" id="licenseState"class="form-control" required ng-model="student.License.State" ng-options="key as value for (key, value) in licenseFormats" check-state license-formats="licenseFormats"> // in the controller $scope.licenseFormats = { 'OR': 'Oregon', 'WA': 'Washington', }; // the directive app.directive('checkState', function() { return { scope: { licenseFormats: '=' }, restrict: 'A', require: 'ngModel', link: function(scope, element, attributes, ngModel) { // defining the validator here ngModel.$validators.state = function(modelValue) { returnObject.keys(scope.licenseFormats).indexOf(modelValue) > -1; } } } }); Copy Share You may like these postsCasperjs And Jquery With Chained SelectsUse Db Results To Populate 1st Dropmenu, And 1st Dropmenu Value To Populate 2ndAccessing Selected Dropdown Items Using JavaHow Can I Set The Width Of Select Box Options? Post a Comment for "Angularjs Select Doesn't Error When Model Value Not In Options"
Post a Comment for "Angularjs Select Doesn't Error When Model Value Not In Options"