Angular ngOptions 'track by' and null value validation issue

617 Views Asked by At

I have a select list using ngOptions and the 'track by' feature like this:

<select validdate="{{date}}" ng-model="code" ng-options="code.description for code in codelist track by code.value">
        <option value=""></option>
</select>

The code object has various properties, including a start and enddate which determines the validity of the code. There is a seperate 'date' property which is used to check if the code can be selected or not. For this validdate-directive I need the whole object, therefore I use the track by and cannot use the 'as' to fill the ng-model property.

This works properly, except for the initial null value.

When the validation returns false (and marks the select-box accordingly) and the user then selects the null value, the validation doesn't get reset.

The validator isn't called, even though the ng-model property 'code' changes from an object to a null-value. It seems that because of the track by, it does not trigger the validation directive. Does anyone know a solution for this?

1

There are 1 best solutions below

0
On

It was a bug in my particular version of Angular, 1.3.8. Upgrading solved it, but for reference this JS Fiddle shows the bug (and changeing the version there solves the bug) http://jsfiddle.net/2tvy2jgh/1/

enter code here