[%~ # Some illustrious documentation to get you started: # # The macros defined are to generate markup to save people from copy and pasting # markup. They copy and paste hashes instead, which should be safer (in theory) # # The macros for forms are: # * text_field - A simple text field, pass in type to override input type # * password_field - A password field, equivalent to # text_field({ type => 'password', ... }) # * textarea_field - A textarea field # * readonly_field - A display-only field, with a hidden input # * select_field - A [% info.value %] [% IF info.link || info.required || info.error || info.success || info.warning %] [% IF info.required %][% c.loc('FIELD REQUIRED SPLAT') %][% END; info.error; info.warning; info.success %] [%~ IF info.link %][%~ END ~%] [% END %] [% IF info.support %]

[% c.loc(info.support) %]

[% END %] [%~ IF info.link ~%]
[%~ END ~%]
[% END; MACRO select_field(info) BLOCK; IF !info.defined('value_method'); info.value_method = 'value'; END; IF !info.defined('label_method'); info.label_method = 'label'; END; IF !info.value && results.${context.scope}; value_name = info.name; IF context.scope; value_name = value_name.replace("${context.scope}.", ""); END; info.value = results.${context.scope}.get_original_value(value_name); END; IF !info.error && messages.for_scope(context.scope); value_name = info.name; IF context.scope; value_name = value_name.replace("^${context.scope}.", ""); END; info.error = messages.for_scope(context.scope).for_subject(value_name).first_message.id; END; %] [%~ IF info.dynamic_array =%][% IF info.options.size == 0; info.options.push(c.loc('Please select [_1]', [ info.value_from ] ) ); END; END %]
[% label_field(info) %]
<[% IF info.type == 'radio'; "div"; ELSE; "select"; END %] id="form_[% info.name %]" name="[% info.name %]" [%~ IF info.classes %] class="[% info.classes.join(' ') %]"[%~ END ~%] [%~ IF info.disabled %] disabled="disabled"[%~ END ~%] [%~ FOREACH datum IN info.data.pairs %] data-[% datum.key %]="[% datum.value %]"[%~ END ~%]> [% IF info.type != "radio" && info.default_option %] [% IF info.type == 'radio' %] [% ELSE %] [% END %] [% END %] [% IF info.optgroups; info.options = []; DEFAULT info.children = 'children'; FOREACH parent IN info.optgroups; info.options.push({ optgroup => parent.${info.label_method} }); FOREACH child IN parent.children; info.options.push(child); END; END; END %] [% has_optgroup = 0; FOREACH item = info.options; IF item.optgroup; has_optgroup = 1; IF !loop.first %][% END; %][% ELSE; IF info.defined('value_method') && item.keys.defined; SET this_value = item.${info.value_method}; ELSE; SET this_value = item; END; IF info.defined('label_method') && item.keys.defined; SET this_name = item.${info.label_method}; ELSE; SET this_name = item; END; IF info.defined('elide'); this_name = string_trunc.elide(this_name, info.elide); END; %][% IF info.type == "radio" %][% info.radio_trailing %] [% ELSE %][% END %] [% END; # Not an optgroup %] [% END; IF has_optgroup %][% END %] [% IF info.type != 'radio' %][% END %] [% IF info.type == 'radio' %] [% IF info.required %][% c.loc('FIELD REQUIRED SPLAT') %][% END %]
[% ELSE %] [% IF info.required || info.error || info.success || info.warning %] [% END %] [% IF info.required %][% c.loc('FIELD REQUIRED SPLAT') %][% END; info.error; info.warning; info.success %] [% END %] [% IF info.support %]

[% c.loc(info.support) %]

[% END %]
[% END; MACRO password_field(info) BLOCK; info.type = 'password'; info.value = ''; # Force values to not be set. text_field(info); END; MACRO datetime_field(info) BLOCK; IF !info.defined('type'); info.type = 'date'; END; IF !info.defined('value'); IF results.${context.scope}; value_name = info.name; IF context.scope; value_name = value_name.replace("^${context.scope}.", ""); END; info.value = results.${context.scope}.get_original_value(value_name); END; IF !info.defined('value') && info.default_value; info.value = info.default_value; END; END; IF !info.error && messages.for_scope(context.scope); value_name = info.name; IF context.scope; value_name = value_name.replace("^${context.scope}.", ""); END; message = messages.for_scope(context.scope).for_subject(value_name).first_message; IF message; info.${message.level} = c.loc(message.id); END; END; IF info.filter && info.value; f = info.filter; IF f == "join"; info.value = info.value.join(', '); ELSE; TRY; info.value = FILTER $f; info.value; END; CATCH; "Error applying filter to ${info.name}!"; END; END; END; IF info.defined('value') && info.defined('timezone'); info.value = set_timezone(info.value, info.timezone); END; DEFAULT info.id = "form_" _ info.name.replace('\.', '_'); %]
[% label_field(info) %]
[%~ IF info.prepend || info.append ~%]
[%~ IF info.prepend ~%][% info.prepend %][%~ END ~%] [%~ END ~%] [%~ IF info.append ~%][% info.append %][%~ END ~%] [%~ IF info.prepend || info.append ~%]
[%~ END ~%] [% IF info.required || info.error || info.success || info.warning %] [% IF info.required %][% c.loc('FIELD REQUIRED SPLAT') %][% END; info.error; info.warning; info.success %] [% END %] [% IF info.support %]

[% c.loc(info.support) %]

[% END %]
[% END; MACRO text_field(info) BLOCK; IF !info.defined('value'); IF results.${context.scope}; value_name = info.name; IF context.scope; value_name = value_name.replace("^${context.scope}.", ""); END; info.value = results.${context.scope}.get_original_value(value_name); END; IF !info.defined('value') && info.default_value; info.value = info.default_value; END; END; IF !info.error && messages.for_scope(context.scope); value_name = info.name; IF context.scope; value_name = value_name.replace("^${context.scope}.", ""); END; message = messages.for_scope(context.scope).for_subject(value_name).first_message; IF message; info.${message.level} = c.loc(message.id); END; END; IF info.filter && info.value; f = info.filter; IF f == "join"; info.value = info.value.join(', '); ELSE; TRY; info.value = FILTER $f; info.value; END; CATCH; "Error applying filter to ${info.name}!"; END; END; END; DEFAULT info.id = "form_" _ info.name.replace('\.', '_'); %]
[% label_field(info) %]
[%~ IF info.prepend || info.append ~%]
[%~ IF info.prepend ~%][% info.prepend %][%~ END ~%] [%~ END ~%] [%~ IF info.append ~%][% info.append %][%~ END ~%] [%~ IF info.prepend || info.append ~%]
[%~ END ~%] [% IF info.required || info.error || info.success || info.warning %] [% IF info.required %][% c.loc('FIELD REQUIRED SPLAT') %][% END; info.error; info.warning; info.success %] [% END %] [% IF info.support %]

[% c.loc(info.support) %]

[% END %]
[% END; MACRO textarea_field(info) BLOCK; IF !info.defined('value'); IF results.${context.scope}; value_name = info.name; IF context.scope; value_name = value_name.replace("^${context.scope}.", ""); END; info.value = results.${context.scope}.get_original_value(value_name); END; IF !info.defined('value') && info.default_value; info.value = info.default_value; END; END; IF !info.error && messages.for_scope(context.scope); value_name = info.name; IF context.scope; value_name = value_name.replace("^${context.scope}.", ""); END; message = messages.for_scope(context.scope).for_subject(value_name).first_message; IF message; info.${message.level} = c.loc(message.id); END; END; %]
[% label_field(info) %]
[% IF info.error || info.success || info.warning %] [% IF info.required %][% c.loc('FIELD REQUIRED SPLAT') %][% END; info.error; info.warning; info.success %] [% END %] [% IF info.support %]

[% c.loc(info.support) %]

[% END %]
[% END; MACRO checkboxes(info) BLOCK; IF !info.defined('value') && !info.defined('selected'); temp = []; IF results.${context.scope}; value_name = info.name; IF context.scope; value_name = value_name.replace("^${context.scope}.", ""); END; temp = results.${context.scope}.get_original_value(value_name); END; IF temp.size == 0 && ( info.defined('default_value') || info.defined('default_selected') ); temp = info.default_selected || info.default_value; END; info.selected = {}; FOREACH v IN temp; info.selected.$v = v; END; END; IF !info.error && messages.for_scope(context.scope); value_name = info.name; IF context.scope; value_name = value_name.replace("^${context.scope}.", ""); END; IF message; info.${message.level} = c.loc(message.id); END; END; %]
[% label_field(info) %]
[% FOREACH item = info.options; IF info.defined('value_method'); SET this_value = item.${info.value_method}; ELSE; SET this_value = item; END; IF info.defined('value_method'); SET this_name = item.${info.label_method}; ELSE; SET this_name = item; END; %] [% END %] [% IF info.required || info.error || info.success || info.warning %]

[% IF info.required %][% c.loc('FIELD REQUIRED SPLAT') %][% END %] [% info.error; info.warning; info.success %]

[% END %]
[% END ~%] [%~ MACRO checkbox(info) BLOCK; IF !info.defined('checked') && results.${context.scope}; value_name = info.name; IF context.scope; value_name = value_name.replace("${context.scope}.", ""); END; info.checked = results.${context.scope}.get_original_value(value_name); END; IF !info.defined('checked'); IF results.${context.scope}; value_name = info.name; IF context.scope; value_name = value_name.replace("^${context.scope}.", ""); END; info.checked = results.${context.scope}.get_original_value(value_name); END; IF !info.defined('checked') && info.default_checked; info.checked = info.default_checked; END; END; IF !info.error && messages.for_scope(context.scope); value_name = info.name; IF context.scope; value_name = value_name.replace("^${context.scope}.", ""); END; IF message; info.${message.level} = c.loc(message.id); END; END; %]
[% label_field(info) %]
[% IF info.required || info.error || info.success || info.warning %] [% IF info.required %][% c.loc('FIELD REQUIRED SPLAT') %][% END; info.error; info.warning; info.success %] [% END %] [% IF info.support %]

[% c.loc(info.support) %]

[% END %]
[% END ~%]