Django, setting selected="selected" on a radio input -


A simple form with ModelChoiceField is displayed as a radio button (inherited widget).

A change event for each post I am using, each user selects a radio button:

  shipping_choice = shippingChoiceField (queryset = ShippingMethods.objects. All), empty_labil = none, widget = forms.RadioSelect (attrs = {'Class': 'order', 'onchange': '$ ("# shipping_choice"). Submit ()',})))  

I need the radio that the user selected thought, the page is actually "selected" when reloaded.

Adding an additional 'ARR' selected will not be, 'because it should be done when users actually make the first option. P

Form has a initial attribute that you can use:

Your code (initial = {'shipping_choice': current_choice})

Again, I think you're using ModelF orm , in this case, you should just enclose the example:

  form = YourForm (example = order) # where "order" is your example ...  

Or maybe you do not understand that a form can be bound to data:

  if request.method == 'POST': order_form = YourForm ( Eta = Request.POST) Other: order_form = YourForm ()  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -