Friday, November 25, 2016

Best practice for implementing a dynamic "other" field in a group of radio buttons?

Hi all,

I'm working on a form that has to support a few groups of radio buttons. I'm wondering if there is a recommended way to do an "other" radio button that can be dynamically set by the user. Like the user can select the "other" radio button and enter a custom string to be associated with their "other" selection. My model is set up like this:

    GENDER_CHOICES
= (
       
('M', 'Man'),
       
('W', 'Woman'),
       
('N', 'Prefer not to answer'),
       
('O', 'Other'),
   
)
    gender
= models.CharField(
        max_length
=1,
        choices
=GENDER_CHOICES,
       
default='',
        blank
=True
   
)


This is good but I would like for the user to be able to define what string the "O" choice points to. Kinda like this from a google doc:













Is there an easy way to do this with django forms?

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/509a9340-1cbf-4999-84fa-c705b45e4bda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment