misc: add dynamic change of options to radio buttons (#48922)
This commit is contained in:
parent
bbcda9aa66
commit
a63ca258a1
|
@ -310,7 +310,25 @@ $(function() {
|
|||
} else {
|
||||
$widget.hide();
|
||||
}
|
||||
if (value.items) {
|
||||
if (value.items && $widget.is('.RadiobuttonsWidget')) {
|
||||
var current_value = $widget.find('input:checked').val();
|
||||
var $hint = $widget.find('.hint').detach();
|
||||
var input_name = $widget.data('widget-name');
|
||||
var $content = $widget.find('.content');
|
||||
$content.empty();
|
||||
for (var i=0; i<value.items.length; i++) {
|
||||
var $label = $('<label></label>');
|
||||
var $input = $('<input>', {type: 'radio', value: value.items[i].id, name: input_name});
|
||||
if (value.items[i].id == current_value) {
|
||||
$input.attr('checked', 'checked');
|
||||
}
|
||||
var $span = $('<span></span>', {text: value.items[i].text});
|
||||
$input.appendTo($label);
|
||||
$span.appendTo($label);
|
||||
$label.appendTo($content);
|
||||
}
|
||||
$hint.appendTo($content);
|
||||
} else if (value.items) {
|
||||
// replace <select> contents
|
||||
var $select = $widget.find('select');
|
||||
var current_value = $select.val();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
{% if widget.is_prefilled %}widget-prefilled{% endif %}"
|
||||
{% if widget.is_hidden %}style="display: none"{% endif %}
|
||||
{% if widget.field %}data-field-id="{{ widget.field.id }}"{% endif %}
|
||||
data-widget-name="{{ widget.name }}"
|
||||
{% if widget.div_id %}id="{{widget.div_id}}" data-valuecontainerid="form_{{widget.name}}"{% endif %}
|
||||
{% for attr in widget.prefill_attributes %}
|
||||
data-{{attr}}="{{widget.prefill_attributes|get:attr}}"
|
||||
|
|
Loading…
Reference in New Issue