If you can, populate the widget with all available choices and then use 
your JS/AJAX to limit/hide some?



On Saturday, September 21, 2013 6:32:03 PM UTC-5, luke lukes wrote:
>
> Hi everyone.
>
> I'm stucking with a ModelForm in the admin. I have two ChoicheField which 
> are populated with choices in __init__:
>
> self.fields['city'] = forms.ChoiceField(
>     required=False,
> )
> self.fields['city'].choices=get_cities_tuple(region_code=region_code)
> self.fields['city'].initial = my_initial_city_value
>
> self.fields['zip'] = forms.ChoiceField(
>     required=False,
> )
> self.fields['zip'].choices=get_cities_tuple(region_code=region_code, 
> city_name=city_name)
> self.fields['zip'].initial = my_initial_zip_value
>
>
> now the options of those html select rendered are dinamically updated 
> through ajax functions. 
> The problem is that while saving, the selected options is recognized as 
> not valid cause is not in the initial choices:
>
> Select a valid choice. <my_choiche> is not one of the available choices.
>
> Any idea on how to solve it? 
>
> Maybe subclassing the original ChoiceField or the Select widget?
>
> Many thanks
> LuKe
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to