Refined the form fields html bindings

This commit is contained in:
Franck Allimant
2014-07-03 16:26:37 +02:00
parent c0541e3aa2
commit c70a296ff2
17 changed files with 315 additions and 372 deletions

View File

@@ -0,0 +1,21 @@
{*
This file defines the standard fields attributes, depending on input types.
In addition to the standard form_field block output, this fragment uses the following additional variables :
- field_template : the template style ('standard', or somethingelse)
- field_value : the value of the input field, which is used if the form_field value is empty.
- field_extra_class : an extra class to add to the input class (see form-field-attributes-standard-renderer.html)
*}
{if $type == 'hidden'}
id="{$label_attr.for}" name="{$name}" value="{$value}"
{elseif $type == 'checkbox' || $type == 'radio'}
class="{$field_extra_class}" type="checkbox" id="{$label_attr.for}" name="{$name}" value="{$value}" {if $checked}checked="checked"{/if}
{elseif $type == 'choice'}
{if $multiple}multiple{/if} {if $lattr_list.size}size="{$lattr_list.size}"{/if} {if $required}aria-required="true" required{/if} id="{$label_attr.for}" name="{$name}"class="form-control class="{$field_extra_class}"
{elseif $type == 'textarea'}
{if $attr_list.rows}rows="{$attr_list.rows}"{/if} {if $required}aria-required="true" required{/if} placeholder="{$attr_list.placeholder|default:$label}" id="{$label_attr.for}" name="{$name}" class="form-control {$field_extra_class}" title="{$label}"
{else}
{if $required}aria-required="true" required{/if} placeholder="{$attr_list.placeholder|default:$label}" id="{$label_attr.for}" name="{$name}" value="{$value}" class="form-control {$field_extra_class}"
{/if}

View File

@@ -0,0 +1,126 @@
{*
This file bind a form field to an HTML representation. In addition to the standard form_field block output, this
fragment uses the following additional variables :
- field_template : the template style ('standard', or somethingelse)
- field_value : the value of the input field, which is used if the form_field value is empty.
- field_extra_class : an extra class to add to the input class (see form-field-attributes-standard-renderer.html)
- content : if this variable is not empty, we assume that it contains the input field definition. Used by the
custom_render_form_field block to pass a custom representation of the input field.
*}
{* Use the optionnal $field_value parameter if no value is defined *}
{if empty($value)}
{$value = $field_value}
{/if}
{* Synthetize an ID if none was given *}
{if empty({$label_attr.for})}
{$label_attr.for = "id-{$field_name}"}
{/if}
{* Get standard fields attributes *}
{capture assign=attributes}
{include file="forms/form-field-attributes-$field_template-renderer.html"}
{/capture}
{if $type == 'hidden'}
<input type="hidden" {$attributes nofilter} />
{elseif $type == 'checkbox'}
<div class="checkbox {if $error}has-error{/if}">
<label>
{if $content == ''}
<input type="checkbox" {$attributes nofilter}>
{$label} {if $required} <span class="required">*</span>{/if}
{else}
{$content nofilter}
{/if}
{form_error form=$form field=$field_name}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
</div>
{elseif $type == 'radio'}
<div class="radio {if $error}has-error{/if}">
<label>
{if $content == ''}
<input type="radio" {$attributes nofilter}>
{$label} {if $required} <span class="required">*</span>{/if}
{else}
{$content nofilter}
{/if}
{form_error form=$form field=$field_name}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
</div>
{else}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">
{$label} {if $required} <span class="required">*</span>{/if}
{form_error form=$form field=$field_name}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
{if $multiple}
<span class="label-help-block">{intl l='Use Ctrl+click to select (or deselect) more that one item'}</span>
{/if}
{if $content == ''}
{if $type == 'choice'}
<select {$attributes nofilter}>
{foreach $choices as $choice}
<option value="{$choice->value}" {if (is_array($value) && in_array($choice->value, $value)) || $choice->value == $value}selected="selected"{/if}>{$choice->label}
{/foreach}
</select>
{elseif $type == 'textarea'}
<textarea {$attributes nofilter}>{$value}</textarea>
{elseif $type == 'money'}
<div class="input-group">
<input type="number" {$attributes nofilter} />
<span class="input-group-addon">{loop name="input.addon" type="currency" default_only="true"}{$SYMBOL}{/loop}</span>
</div>
{else}
{$text_types = ['text', 'password', 'number', 'money', 'integer', 'time', 'date', 'datetime', 'email', 'url', 'file']}
{if in_array($type, $text_types)}
{if $type == 'integer' || $type == 'money'}{$type='number'}{/if}
<input type="{$type}" {$attributes nofilter} />
{else}
<div class="alert alert-danger">{intl l="Unsupported field type '%type' in form-field.html" type=$type}</div>
{/if}
{/if}
{else}
{$content nofilter}
{/if}
{if ! empty($label_attr.help)}
<span class="help-block">{$label_attr.help}</span>
{/if}
</div>
{/if}

View File

@@ -1,90 +0,0 @@
{form_field form=$form field=$field_name}
{* Use the optionnal $field_value parameter if no value is defined *}
{if empty($value)}
{$value = $field_value}
{/if}
{* Synthetize an ID if none was given *}
{if empty({$label_attr.for})}
{$label_attr.for = "id-{$field_name}"}
{/if}
{if $type == 'hidden'}
<input type="hidden" id="{$label_attr.for}" name="{$name}" value="{$value}" />
{elseif $type == 'checkbox'}
<div class="checkbox {if $error}has-error{/if}">
<label>
<input class="{$field_extra_class}" type="checkbox" id="{$label_attr.for}" name="{$name}" value="{$value}" {if $checked}checked="checked"{/if}>
{$label} {if $required} <span class="required">*</span>{/if}
{form_error form=$form field=$field_name}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
</div>
{else}
<div class="form-group {if $error}has-error{/if}">
{admin_form_field_label form=$form name=$field_name label_attr=$label_attr}
{if $multiple}
<span class="label-help-block">{intl l='Use Ctrl+click to select (or deselect) more that one item'}</span>
{/if}
{$lang_code = 0}
{if $label_attr.i18n == 'default'}
{loop type="lang" name="default-lang" default_only="1"}
{$lang_code = $CODE}
{$lang_title = $TITLE}
<div class="input-group">
{/loop}
{/if}
{if $type == 'choice'}
<select {if $multiple}multiple{/if} {if $label_attr.size}size="{$label_attr.size}"{/if} {if $required}aria-required="true" required{/if} id="{$label_attr.for}" name="{$name}"class="form-control {$field_extra_class}">
{foreach $choices as $choice}
<option value="{$choice->value}" {if (is_array($value) && in_array($choice->value, $value)) || $choice->value == $value}selected="selected"{/if}>{$choice->label}
{/foreach}
</select>
{elseif $type == 'textarea'}
<textarea {if $label_attr.rows}rows="{$label_attr.rows}"{/if} {if $required}aria-required="true" required{/if} placeholder="{$label_attr.placeholder|default:$label}" id="{$label_attr.for}" name="{$name}" class="form-control {$field_extra_class}" title="{$label}">{$value}</textarea>
{elseif $type == 'money'}
<div class="input-group">
<input type="number" {if $required}aria-required="true" required{/if} placeholder="{$label_attr.placeholder|default:$label}" id="{$label_attr.for}" name="{$name}" value="{$value}" class="form-control {$field_extra_class}" />
<span class="input-group-addon">{loop name="input.addon" type="currency" default_only="true"}{$SYMBOL}{/loop}</span>
</div>
{else}
{$text_types = ['text', 'password', 'number', 'money', 'integer', 'time', 'date', 'datetime', 'email', 'url', 'file']}
{if in_array($type, $text_types)}
{if $type == 'integer' || $type == 'money'}{$type='number'}{/if}
<input type="{$type}" {if $required}aria-required="true" required{/if} placeholder="{$label_attr.placeholder|default:$label}" id="{$label_attr.for}" name="{$name}" value="{$value}" class="form-control {$field_extra_class}" />
{else}
<div class="alert alert-danger">{intl l="Unsupported field type '%type' in form-field.html" type=$type}</div>
{/if}
{/if}
{if $lang_code}
<span class="input-group-addon"><img src="{image file="assets/img/flags/{$lang_code}.png"}" alt="{$lang_title}" /></span>
</div>
{/if}
{if ! empty($label_attr.help)}
<span class="help-block">{$label_attr.help}</span>
{/if}
</div>
{/if}
{/form_field}

View File

@@ -1,8 +0,0 @@
<label for="{$label_attr.for}" class="control-label">
{$label} {if $required} <span class="required">*</span>{/if}
{form_error form=$form field=$field_name}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>