For various reasons I have been creatin a custom property editor based on a dropdown. This includes extra data-attributes on the options, so I believe the only way to populate these is using ng-repeat
The problem is that when this is output to the browser, angularjs outputs a new option automatically when creating a new record because model.value does not match the value of any of the options (naturally - it's a new record)
<select data-id="myRegion" onchange="selectParentChange('myRegion')" ng-model="model.value" class="ng-pristine ng-valid">
<option value="? string: ?">
</option>
<!-- ngRepeat: item in opts --><option repeat-end="onEnd()" ng-repeat="item in opts" value="1" ng-selected="false" data-parentvalue="-1" class="ng-scope ng-binding"> All Regions
</option><option repeat-end="onEnd()" ng-repeat="item in opts" value="2" ng-selected="false" data-parentvalue="-1" class="ng-scope ng-binding">
Region 1
</option><option repeat-end="onEnd()" ng-repeat="item in opts" value="5" ng-selected="false" data-parentvalue="-1" class="ng-scope ng-binding">
Region 2
</option><option repeat-end="onEnd()" ng-repeat="item in opts" value="4" ng-selected="false" data-parentvalue="-1" class="ng-scope ng-binding">
Region 3
</option><option repeat-end="onEnd()" ng-repeat="item in opts" value="3" ng-selected="false" data-parentvalue="-1" class="ng-scope ng-binding">
Region 4
</option>
</select>
Ie the problem is there is now
<option value="? string: ?">
which means if property is set to 'Field is mandatory' it won't throw an error (I assume Umbraco only throws an error if the value is null?) on save.
Standard Umbraco select dropdowns don't do this, so there must be some code I am missing, or is there a work around?
I was thinking about doing my own validation, but can't find a way to access the Umbraco 'Field is mandatory' flag in a controller.
(oddly, as a postscript, even when I load an existing document which does have a value set and it does match an option, I still get the rogue option sometimes. I am wondering if it's a timing issue)
Angularjs ng-repeat problem
For various reasons I have been creatin a custom property editor based on a dropdown. This includes extra data-attributes on the options, so I believe the only way to populate these is using ng-repeat
I am creating opts in the controller eg
..loop through data ...
finally
The problem is that when this is output to the browser, angularjs outputs a new option automatically when creating a new record because model.value does not match the value of any of the options (naturally - it's a new record)
Ie the problem is there is now
which means if property is set to 'Field is mandatory' it won't throw an error (I assume Umbraco only throws an error if the value is null?) on save.
Standard Umbraco select dropdowns don't do this, so there must be some code I am missing, or is there a work around?
I was thinking about doing my own validation, but can't find a way to access the Umbraco 'Field is mandatory' flag in a controller.
(oddly, as a postscript, even when I load an existing document which does have a value set and it does match an option, I still get the rogue option sometimes. I am wondering if it's a timing issue)
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.