Ticket #16149: select_with_disabled.diff
File select_with_disabled.diff, 1.7 KB (added by , 13 years ago) |
---|
-
django/forms/widgets.py
503 503 return bool(initial) != bool(data) 504 504 505 505 class Select(Widget): 506 def __init__(self, attrs=None, choices=() ):506 def __init__(self, attrs=None, choices=(), disabled_choices=()): 507 507 super(Select, self).__init__(attrs) 508 508 # choices can be any iterable, but we may need to render this widget 509 509 # multiple times. Thus, collapse it into a list so it can be consumed 510 510 # more than once. 511 511 self.choices = list(choices) 512 self.disabled_choices = frozenset(disabled_choices) 512 513 513 514 def render(self, name, value, attrs=None, choices=()): 514 515 if value is None: value = '' … … 522 523 523 524 def render_option(self, selected_choices, option_value, option_label): 524 525 option_value = force_unicode(option_value) 525 selected_html = (option_value in selected_choices) and u' selected="selected"' or '' 526 return u'<option value="%s"%s>%s</option>' % ( 527 escape(option_value), selected_html, 526 if (option_value in selected_choices): 527 selected_html = u' selected="selected"' 528 else: 529 selected_html = '' 530 if (option_value in self.disabled_choices): 531 disabled_html = u' disabled="disabled"' 532 else: 533 disabled_html = '' 534 return u'<option value="%s"%s%s>%s</option>' % ( 535 escape(option_value), selected_html, disabled_html, 528 536 conditional_escape(force_unicode(option_label))) 529 537 530 538 def render_options(self, choices, selected_choices):