I have:
<select name="club" id="club" ng-model="currentUser.club_id" ng-options="club.id as club.name for club in clubs | filter:{ country_id: currentUser.country_id }" required></select>
I'm happy that, since I'm a filter
list clubs
, there are times when it <select>
doesn't <option>
, which means the attribute required
makes the form unsubmittable.
I could do
<select ng-required="(clubs | filter:{ country_id: currentUser.country_id }).length"></select>
but maybe there is a more elegant way to do it. Something like:
<select ng-required="$element.options.length"></select>
Is my intuition correct? How can I do this?
source
to share