Introduced the automatic form fields binding.
This commit is contained in:
90
templates/backOffice/default/forms/form-field.html
Normal file
90
templates/backOffice/default/forms/form-field.html
Normal file
@@ -0,0 +1,90 @@
|
||||
{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}
|
||||
8
templates/backOffice/default/forms/form-label.html
Normal file
8
templates/backOffice/default/forms/form-label.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<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>
|
||||
Reference in New Issue
Block a user