jrief / django-angular

Let AngularJS play well with Django
http://django-angular.awesto.com/
MIT License
1.23k stars 294 forks source link

Fix select with edit (Issue #68). #231

Closed adrienbrunet closed 8 years ago

adrienbrunet commented 8 years ago

The problem appears when you have a form (not bound) with choiceField (foreignkeys and m2m) and at some point, you initialize it with angular. What happens when you get a json serialized representation of your model is, if you have foreignkey, you get the pk as a number. BUT, a select expects the value to be a string (!). Angular then adds a new option value to the select which make no sens.

In the angular docs, an example is shown with a convertToNumber directive. https://docs.angularjs.org/api/ng/directive/select (last example on the page) I only reuse the formatters part as we need to ensure it stays generic.

Cheers