From 5a48b4ac573e56b74058a905f24e0834f2e314b7 Mon Sep 17 00:00:00 2001 From: ralf Date: Thu, 6 Jun 2024 13:34:42 +0200 Subject: [PATCH] optional name attribute to group radio-buttons instead of the default id --- api/js/etemplate/et2_widget_radiobox.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/api/js/etemplate/et2_widget_radiobox.ts b/api/js/etemplate/et2_widget_radiobox.ts index 7c23c89555..a8406826d3 100644 --- a/api/js/etemplate/et2_widget_radiobox.ts +++ b/api/js/etemplate/et2_widget_radiobox.ts @@ -48,6 +48,12 @@ export class et2_radiobox extends et2_inputWidget "type": "string", "default": "", "description": "What should be displayed when readonly and not selected" + }, + name: { + "name": "Name of radio-group", + "type": "string", + "default": "", + "description": "Used to group radio-buttons, defaults to id of radio-button" } }; @@ -96,7 +102,10 @@ export class et2_radiobox extends et2_inputWidget super.set_id(_id); this.dom_id = this.dom_id.replace('[]', '')+'-'+this.options.set_value; - if (this.input) this.input.attr('id', this.dom_id); + if (this.input) { + this.input.attr('id', this.dom_id); + if (this.options.name) this.input.attr('name', this.options.name); + } } /** @@ -122,7 +131,7 @@ export class et2_radiobox extends et2_inputWidget { this.getRoot().iterateOver(function(radio) { - if (radio.id == this.id) + if (radio.id == this.id && (!this.options.name || this.options.name == radio.options.name)) { radio.input.prop('checked', _value == radio.options.set_value); } @@ -141,7 +150,8 @@ export class et2_radiobox extends et2_inputWidget this.getRoot().iterateOver(function(radio) { values.push(radio.options.set_value); - if (radio.id == this.id && radio.input && radio.input.prop('checked')) + if (radio.id == this.id && radio.input && (!this.options.name || this.options.name == radio.options.name) && + radio.input.prop('checked')) { val = radio.options.set_value; } @@ -486,5 +496,4 @@ export class et2_radioGroup extends et2_valueWidget implements et2_IDetachedDOM } // No such tag as 'radiogroup', but it needs something -et2_register_widget(et2_radioGroup, ["radiogroup"]); - +et2_register_widget(et2_radioGroup, ["radiogroup"]); \ No newline at end of file