0

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?

Sagi Mann
  • 2,967
  • 6
  • 39
  • 72
  • you can use ng options like `ng-model="obj.arrItem.id" ng-options="arrItem.name for arrItem in arrItems"` while submiting form use value from ng model – Ranjith S Nov 27 '15 at 16:12
  • on your select tag do you use ng-model? can you create a fiddle? – Radu Nov 27 '15 at 16:14
  • The point is I want to use a dropdown (ul, li) instead of a select... But I want it to behave like a select... – Sagi Mann Nov 27 '15 at 17:44

1 Answers1

0

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!

Sagi Mann
  • 2,967
  • 6
  • 39
  • 72