diff --git a/render/box_construct.c b/render/box_construct.c index b259e6a1f..4d9796932 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -2853,7 +2853,7 @@ bool box_select_add_option(struct form_control *control, dom_node *n) if (text_nowrap == NULL) goto no_memory; - if (form_add_option(control, value, text_nowrap, selected) == false) + if (form_add_option(control, value, text_nowrap, selected, n) == false) goto no_memory; free(text); diff --git a/render/form.c b/render/form.c index 254d2cffb..aa6661cfa 100644 --- a/render/form.c +++ b/render/form.c @@ -278,10 +278,11 @@ void form_free_control(struct form_control *control) * \param value value of option, used directly (not copied) * \param text text for option, used directly (not copied) * \param selected this option is selected + * \param node the DOM node this option is associated with * \return true on success, false on memory exhaustion */ bool form_add_option(struct form_control *control, char *value, char *text, - bool selected) + bool selected, void *node) { struct form_option *option; @@ -312,6 +313,8 @@ bool form_add_option(struct form_control *control, char *value, char *text, control->data.select.num_items++; + option->node = node; + return true; } @@ -1140,12 +1143,15 @@ static void form__select_process_selection(html_content *html, if (control->data.select.multiple) { if (o->selected) { o->selected = false; + dom_html_option_element_set_selected(o->node, false); control->data.select.num_selected--; } else { o->selected = true; + dom_html_option_element_set_selected(o->node, true); control->data.select.num_selected++; } } else { + dom_html_option_element_set_selected(o->node, true); o->selected = true; } } @@ -1434,11 +1440,13 @@ void form_radio_set(html_content *html, if (control->selected) { control->selected = false; + dom_html_input_element_set_checked(control->node, false); html__redraw_a_box(html, control->box); } } radio->selected = true; + dom_html_input_element_set_checked(radio->node, true); html__redraw_a_box(html, radio->box); } diff --git a/render/form.h b/render/form.h index c03ea8e99..b538c3b33 100644 --- a/render/form.h +++ b/render/form.h @@ -126,6 +126,7 @@ struct form_control { /** Option in a select. */ struct form_option { + void *node; /**< Corresponding DOM node */ bool selected; bool initial_selected; char *value; @@ -154,7 +155,7 @@ struct form_control *form_new_control(void *node, form_control_type type); void form_add_control(struct form *form, struct form_control *control); void form_free_control(struct form_control *control); bool form_add_option(struct form_control *control, char *value, char *text, - bool selected); + bool selected, void *node); bool form_successful_controls(struct form *form, struct form_control *submit_button, struct fetch_multipart_data **successful_controls);