diff --git a/web/CXM_form.anubis b/web/CXM_form.anubis index 46a73b2..6ebd292 100644 --- a/web/CXM_form.anubis +++ b/web/CXM_form.anubis @@ -12,6 +12,7 @@ read tools/basis.anubis read system/string.anubis read calexium_lib/web/CXM_common.anubis +read calexium_lib/web/CXM_web_arg_utils.anubis read calexium_lib/web/CXM_making_a_web_site.anubis read calexium_lib/web/CXM_html_tooltip.anubis read calexium_lib/web/CXM_widgets.anubis @@ -95,6 +96,7 @@ public type CXM_Form_Field: List(String) items, Maybe(InitialValue) selected, Mandatory mandatory), + selector_c (List(InputAttrs) options, String label, HtmlId id, @@ -314,7 +316,8 @@ public define CXM_Form_Field public define HTML_In_Form cxm_format_form_field ( - CXM_Form_Field ff + CXM_Form_Field ff, + List(Web_arg) lwa ) = with star = (Mandatory m) |-> (String) if m is @@ -364,14 +367,14 @@ public define HTML_In_Form message(t) then literal(t), - input(options, label, id, name, init, w, mand) then - text_input([class("in") . options], label + star(mand), id, name, init, pixels(w)), + input(options, label, id, wan, default, w, mand) then + text_input([class("in") . options], label + star(mand), id, wan, init(get_String(lwa, wan.name, default.value)), pixels(w)), input_readonly(options, label, id, name, init, w) then text_input_ro([class("in") . options], label, id, name, init, pixels(w)), - text_area(options, label, id, name, init, w, height, mand) then - text_area([input_attrs([class("in")]) . options], label + star(mand), id, name, init, pixels(w), height), + text_area(options, label, id, wan, default, w, height, mand) then + text_area([input_attrs([class("in")]) . options], label + star(mand), id, wan, init(get_String(lwa, wan.name, default.value)), pixels(w), height), password_input(options, label, id, name, init, w, mand) then password_input([class("in") . options], label + star(mand), id, name, init, pixels(w)), @@ -386,36 +389,43 @@ public define HTML_In_Form if selected is { failure then selector(options, label + star(mand), id, wan, size, items), - success(init) then selector(options, label + star(mand), id, wan, size, items, init), + success(default) then selector(options, label + star(mand), id, wan, size, items, init(get_String(lwa, wan.name, default.value))), }, selector_c(options, label, id, wan, size, items, selected, mand) then if selected is { failure then selector_c(options, label + star(mand), id, wan, size, items), - success(init) then selector_c(options, label + star(mand), id, wan, size, items, init), + success(default) then selector_c(options, label + star(mand), id, wan, size, items, init(get_String(lwa, wan.name, default.value))), }, - checkbox(options, label, id, name, val, checked, mand) then - check_box(options, label + star(mand), id, name, val, checked), + checkbox(options, label, id, wan, val, checked, mand) then + check_box(options, label + star(mand), id, wan, val, get_Bool(lwa, wan.name, checked)), - checkboxr(options, label, id, name, val, checked, mand) then - check_box_r(options, label + star(mand), id, name, val, checked), + checkboxr(options, label, id, wan, val, checked, mand) then + check_box_r(options, label + star(mand), id, wan, val, get_Bool(lwa, wan.name, checked)), - checkbox_hide_show(options, label, name, val, checked, fields) then + checkbox_hide_show(options, label, wan, val, checked, fields) then with div_id = generate_random_string(15), sequence([ - check_box([event(onclick, "checkbox_hide_show_element('"+div_id+"', this);")], label, htmlId(""), name, val, checked), - div([id(div_id), style("display:"+if checked then "block" else "none")], sequence(map((CXM_Form_Field ff2) |-> div([class("form_field")], cxm_format_form_field(ff2)),fields))) + check_box([event(onclick, "checkbox_hide_show_element('"+div_id+"', this);")], label, htmlId(""), wan, val, get_Bool(lwa, wan.name, checked)), + div([id(div_id), style("display:"+if checked then "block" else "none")], sequence(map((CXM_Form_Field ff2) |-> div([class("form_field")], cxm_format_form_field(ff2, lwa)),fields))) ]), - radio_button(options, label, id, name, val, checked, mand) then - radio_button(options, label + star(mand), id, name, val, checked), + radio_button(options, label, id, wan, val, checked, mand) then + radio_button(options, label + star(mand), id, wan, val, get_Bool(lwa, wan.name, checked)), - radio_buttonr(options, label, id, name, val, checked, mand) then - radio_button_r(options, label + star(mand), id, name, val, checked), + radio_buttonr(options, label, id, wan, val, checked, mand) then + radio_button_r(options, label + star(mand), id, wan, val, get_Bool(lwa, wan.name, checked)), radio_button_list (options, label, id, wan, items, selected, mand, wide) then + with new_selected = + if get_String(lwa, wan.name) is + { + failure then selected, + success(value) then success(init(value)) + }, + sequence([ literal(""), div( [class("radiolist")], sequence( @@ -426,13 +436,13 @@ public define HTML_In_Form if item is (wav, item_label) then with id = if id is htmlId(the_id) then htmlId(the_id + "_radio_" + *i), div([class(itemclass)], radio_button_r(options, item_label, id, wan, wav, - if selected is success(v) then wav.value = v.value else false)), + if new_selected is success(v) then wav.value = v.value else false)), items)) ), ]), one_line_fields(fields) then table([nude],[row([], - map((CXM_Form_Field ff2) |-> cell([],cxm_format_form_field(ff2)),fields))]) + map((CXM_Form_Field ff2) |-> cell([],cxm_format_form_field(ff2, lwa)),fields))]) , upload(options, label, id, name, w, mand) then @@ -449,7 +459,7 @@ public define HTML_In_Form partial(p_content) then partial(p_content), input_with_help(input, help_title, help_text, width) then sequence([ - cxm_format_form_field(input), + cxm_format_form_field(input, lwa), html_tooltip(force_String(help_title), help_text, width), ]), @@ -462,49 +472,53 @@ public define HTML_In_Form div([class(htmlClass.class)], literal(" ")), submit(attrs, htmlClass, action_name, mb_label, button_text, extra_operands) then - actioner( same, // TODO change this to allow external URL + actioner( same, // TODO change this to allow external URL if mb_label is { - failure then same, - success(n) then same(n) + failure then same, + success(n) then same(n) }, submit(attrs + [class(htmlClass.class)], button_text), action_name, extra_operands ), - empty then literal("") - }. + empty then literal("") + }. public define HTML_In_Form - cxm_fieldset + cxm_fieldset ( - List(CoreAttrs) options, - String legend, - List(CXM_Form_Field)fields - ) = + List(CoreAttrs) options, + String legend, + List(Web_arg) lwa, + List(CXM_Form_Field) fields + )= sequence([ literal("
")]). + sequence( map((CXM_Form_Field ff) |-> div([class("form_field")], cxm_format_form_field(ff, lwa)), fields) ), + literal("")] + ) + . public define HTML_In_Form cxm_fieldset ( - HtmlId fieldSetId, - List(CXM_Form_Field)fields + HtmlId fieldSetId, + List(Web_arg) lwa, + List(CXM_Form_Field) fields ) = - cxm_fieldset([id(fieldSetId.id), class("aligned")], "", fields). + cxm_fieldset([id(fieldSetId.id), class("aligned")], "", lwa, fields). public define HTML_Off_Form cxm_form ( - String form_name, - List(CoreAttrs) options, - String action_name, + String form_name, + List(CoreAttrs) options, + String action_name, List((String,String)) extra_ops, - List(HTML_In_Form) fieldSets - ) = + List(HTML_In_Form) fieldSets + )= //div([class("formulaire")], form( form_name, [class("formulaire") . options], @@ -534,27 +548,28 @@ public define HTML_Off_Form String form_name, List(CoreAttrs) options, HtmlId fieldSetId, - String action_name, + String action_name, List((String,String)) extra_ops, - + List(Web_arg) lwa, List(CXM_Form_Field) fields ) = cxm_form(form_name, options, action_name, extra_ops, [ - cxm_fieldset([id(fieldSetId.id), class("aligned")], "", fields) + cxm_fieldset([id(fieldSetId.id), class("aligned")], "", lwa, fields) ]). public define HTML_Off_Form cxm_form ( - String form_name, - List(CoreAttrs) options, - HtmlId fieldSetId, - List(CXM_Form_Field) fields + String form_name, + List(CoreAttrs) options, + HtmlId fieldSetId, + List(Web_arg) lwa, + List(CXM_Form_Field) fields ) = cxm_form(form_name, options, [ - cxm_fieldset([id(fieldSetId.id), class("aligned")], "", fields) + cxm_fieldset([id(fieldSetId.id), class("aligned")], "", lwa, fields) ]). public define HTML_Off_Form @@ -568,9 +583,10 @@ public define HTML_Off_Form public define HTML_Off_Form cxm_form ( - String form_name, - HtmlId fieldSetId, + String form_name, + HtmlId fieldSetId, + List(Web_arg) lwa, List(CXM_Form_Field) fields ) = - cxm_form(form_name, [], fieldSetId, fields). + cxm_form(form_name, [], fieldSetId, lwa, fields). -- libgit2 0.21.4