Reputation: 3610
I want to use a dropdown button instead of a select-options in a form. I'm using angular, and the problem is: 1. The dropdown should display the name of the selection but the form should submit its Id instead 2. Changes to the dropdown don't make the form dirty
How do I resolve this?
Upvotes: 0
Views: 630
Reputation: 3610
ok, resolved, it appears I had a very small typeo in the dropdown button's ng-if expression, which caused it to always show "None" instead of the selected item from the list. This led me to think that the selection in the form did not propagate to the model..
anyway, here's my working codepen - I'm using the form field controller's setViewModel to push a value from the dropdown to the hidden input field, and angular takes care of pushing it down to the model while making the form dirty:
form.groupId.$setViewValue(group.id);
Anyway, it seems like the most elegant way (I could find) to do this (except maybe using a directive to compeltely replace the select input..)
Hope this helps!
Upvotes: 0