diff options
| author | José Padilla | 2015-02-20 11:43:12 -0400 |
|---|---|---|
| committer | José Padilla | 2015-02-20 11:43:12 -0400 |
| commit | bb8690cfb3208440c35a5c35eb65562f7e1729cc (patch) | |
| tree | 7aef179196f801036350a2ce39932fbbdc92698e /rest_framework | |
| parent | dc8cc8607763fccc6eb3668ea7e2a976c08dd614 (diff) | |
| download | django-rest-framework-bb8690cfb3208440c35a5c35eb65562f7e1729cc.tar.bz2 | |
Disable select field if no choices available
Diffstat (limited to 'rest_framework')
3 files changed, 21 insertions, 6 deletions
diff --git a/rest_framework/templates/rest_framework/horizontal/select_multiple.html b/rest_framework/templates/rest_framework/horizontal/select_multiple.html index 01c251fb..0735f280 100644 --- a/rest_framework/templates/rest_framework/horizontal/select_multiple.html +++ b/rest_framework/templates/rest_framework/horizontal/select_multiple.html @@ -1,11 +1,16 @@ +{% load i18n %} +{% trans "No items to select." as no_items %} + <div class="form-group"> {% if field.label %} <label class="col-sm-2 control-label {% if style.hide_label %}sr-only{% endif %}">{{ field.label }}</label> {% endif %} <div class="col-sm-10"> - <select multiple class="form-control" name="{{ field.name }}"> + <select multiple {{ field.choices|yesno:",disabled" }} class="form-control" name="{{ field.name }}"> {% for key, text in field.choices.items %} - <option value="{{ key }}" {% if key in field.value %}selected{% endif %}>{{ text }}</option> + <option value="{{ key }}" {% if key in field.value %}selected{% endif %}>{{ text }}</option> + {% empty %} + <option>{{ no_items }}</option> {% endfor %} </select> {% if field.errors %} diff --git a/rest_framework/templates/rest_framework/inline/select_multiple.html b/rest_framework/templates/rest_framework/inline/select_multiple.html index feddf7ab..5a8b2494 100644 --- a/rest_framework/templates/rest_framework/inline/select_multiple.html +++ b/rest_framework/templates/rest_framework/inline/select_multiple.html @@ -1,10 +1,15 @@ +{% load i18n %} +{% trans "No items to select." as no_items %} + <div class="form-group {% if field.errors %}has-error{% endif %}"> {% if field.label %} <label class="sr-only">{{ field.label }}</label> {% endif %} - <select multiple class="form-control" name="{{ field.name }}"> + <select multiple {{ field.choices|yesno:",disabled" }} class="form-control" name="{{ field.name }}"> {% for key, text in field.choices.items %} - <option value="{{ key }}" {% if key in field.value %}selected{% endif %}>{{ text }}</option> + <option value="{{ key }}" {% if key in field.value %}selected{% endif %}>{{ text }}</option> + {% empty %} + <option>{{ no_items }}</option> {% endfor %} </select> </div> diff --git a/rest_framework/templates/rest_framework/vertical/select_multiple.html b/rest_framework/templates/rest_framework/vertical/select_multiple.html index 54839294..81b25c2a 100644 --- a/rest_framework/templates/rest_framework/vertical/select_multiple.html +++ b/rest_framework/templates/rest_framework/vertical/select_multiple.html @@ -1,10 +1,15 @@ +{% load i18n %} +{% trans "No items to select." as no_items %} + <div class="form-group {% if field.errors %}has-error{% endif %}"> {% if field.label %} <label {% if style.hide_label %}class="sr-only"{% endif %}>{{ field.label }}</label> {% endif %} - <select multiple class="form-control" name="{{ field.name }}"> + <select multiple {{ field.choices|yesno:",disabled" }} class="form-control" name="{{ field.name }}"> {% for key, text in field.choices.items %} - <option value="{{ key }}" {% if key in field.value %}selected{% endif %}>{{ text }}</option> + <option value="{{ key }}" {% if key in field.value %}selected{% endif %}>{{ text }}</option> + {% empty %} + <option>{{ no_items }}</option> {% endfor %} </select> {% if field.errors %} |
