angularjs select required not working ng-options

bytez picture bytez · Jul 23, 2014 · Viewed 44.3k times · Source

I am trying to ensure a user selects a value from a select box before submitting the form. This works correctly with static options; it however fails when populating the options via a model using ng-options

Examplehttp://plnkr.co/edit/wRqSCNskLo5c48jy4nQf

I am using AngularJS 1.2.9

Thank you in advance.

Answer

Viktor picture Viktor · Jul 24, 2014

In your example changing the data bound select to the following fixes the required directive. I'm not sure why exactly.

<select ng-model="selectedValue1" ng-options="opt for opt in ['Mazda2','Maxda3']" required>
  <option></option>
</select>