python - django submit form on change -


hello trying submit form when selection option on choicefield

class actionform(forms.form):     """ holds options mailbox management """     choices = ['create new folder', 'delete', 'read', 'unread']     action = forms.choicefield(choices=choices, attrs={'onchange': 'actionform.submit();'}) 

but invallid syntax when try load form. pretty sure attrs={'onchange': 'actionform.submit();'}) problem, not sure how else it.

you need set widget argument on field , pass attrs argument:

action = forms.choicefield(choices=choices,                             widget=forms.select(attrs={'onchange': 'actionform.submit();'})) 

also, choices list should contain items containing 2 things inside:

choices = [(0, 'create new folder'), (1, 'delete'), (2, 'read'), (3, 'unread')] 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -