diff options
author | John-Mark Bell <jmb@netsurf-browser.org> | 2024-02-25 14:57:58 +0000 |
---|---|---|
committer | John-Mark Bell <jmb@netsurf-browser.org> | 2024-02-25 15:00:39 +0000 |
commit | 91b29b626f54bd76710a74c400c2a6c0bdb6a4be (patch) | |
tree | 77f45652d0fb5885df2bbec16f6ef5567d0d002d /content/handlers | |
parent | bce0aa6fc9250395a899996b5e9067b4f370c40d (diff) | |
download | netsurf-91b29b626f54bd76710a74c400c2a6c0bdb6a4be.tar.gz netsurf-91b29b626f54bd76710a74c400c2a6c0bdb6a4be.tar.bz2 |
HTML/forms: fix radio button group handling
Diffstat (limited to 'content/handlers')
-rw-r--r-- | content/handlers/html/form.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/content/handlers/html/form.c b/content/handlers/html/form.c index 8c8120877..9b6768a56 100644 --- a/content/handlers/html/form.c +++ b/content/handlers/html/form.c @@ -2002,20 +2002,33 @@ void form_radio_set(struct form_control *radio) if (radio->selected) return; + /* Clear selected state for other controls in + * the same radio button group */ for (control = radio->form->controls; control != NULL; control = control->next) { + /* Only interested in radio inputs */ if (control->type != GADGET_RADIO) continue; + /* Ignore ourself */ if (control == radio) continue; - if ((control->name != NULL) && - (radio->name != NULL) && + /* Ignore inputs where: + * a) this or the other control have no name attribute + * b) this or the other control have an empty name attribute + * c) the control names do not match + */ + if ((control->name == NULL) || + (radio->name == NULL) || + (control->name[0] == '\0') || + (radio->name[0] == '\0') || strcmp(control->name, radio->name) != 0) continue; + /* Other control is in the same radio button group: clear its + * selected state */ if (control->selected) { control->selected = false; dom_html_input_element_set_checked(control->node, false); |