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

@@ -69,8 +69,8 @@
{form_hidden_fields form=$form}
{admin_form_field form=$form name="success_url" value={url path="/admin/brand"}}
{admin_form_field form=$form name="locale" value={$edit_language_locale}}
{render_form_field form=$form field="success_url" value={url path="/admin/brand"}}
{render_form_field form=$form field="locale" value={$edit_language_locale}}
{if $form_error}
<div class="alert alert-danger">{$form_error_message}</div>
@@ -82,27 +82,17 @@
</div>
<div class="col-md-4">
{admin_form_field form=$form name="visible"}
{render_form_field form=$form field="visible"}
{form_field form=$form field='logo_image_id'}
<div class="form-group {if $error}has-error{/if}">
{admin_form_field_label form=$form name='logo_image_id'}
<select id="{$label_attr.for}" {if $required}aria-required="true" required{/if} name="{$name}" class="form-control brand-image-selector">
<option value="">{intl l="No logo image"}</option>
{loop name="brand-images" type="image" brand=$ID width="90" height="90" resize_mode="crop"}
<option value="{$ID}" data-img-src="{$IMAGE_URL}" {if $LOGO_IMAGE_ID == $ID}selected="selected"{/if}>{$TITLE}</option>
{/loop}
</select>
{if $label_attr.help}
<span class="help-block">{$label_attr.help}</span>
{/if}
</div>
{/form_field}
{custom_render_form_field form=$form field='logo_image_id'}
<select {form_field_attributes form=$form field='logo_image_id' extra_class='brand-image-selector'} >
<option value="">{intl l="No logo image"}</option>
{loop name="brand-images" type="image" brand=$ID width="90" height="90" resize_mode="crop"}
<option value="{$ID}" data-img-src="{$IMAGE_URL}" {if $LOGO_IMAGE_ID == $ID}selected="selected"{/if}>{$TITLE}</option>
{/loop}
</select>
{/custom_render_form_field}
</div>
</div>

View File

@@ -190,12 +190,26 @@
{* Switch edition to the current locale *}
<input type="hidden" name="edit_language_id" value="{$ID}" />
{admin_form_field form=$form name="locale" value=$LOCALE}
{render_form_field form=$form field="locale" value=$LOCALE}
{/loop}
{admin_form_field form=$form name="success_url" value={url path='/admin/brand/update/_ID_'}}
{admin_form_field form=$form name="title"}
{admin_form_field form=$form name="visible"}
{render_form_field form=$form field="success_url" value={url path='/admin/brand/update/_ID_'}}
{custom_render_form_field form=$form field="title"}
{loop type="lang" name="default-lang" default_only="1"}
{* Switch edition to the current locale *}
<input type="hidden" name="edit_language_id" value="{$ID}" />
{render_form_field field="locale" value=$LOCALE}
<div class="input-group">
<input type="text" {$form_field_attributes form=$form field="title" template="toto"}>
<span class="input-group-addon"><img src="{image file="assets/img/flags/{$CODE}.png"}" alt="{$TITLE}" /></span>
</div>
{/loop}
{/custom_render_form_field}
{render_form_field form=$form field="visible"}
{module_include location='brand_create_form'}

View File

@@ -40,8 +40,8 @@
{form_hidden_fields form=$form}
{admin_form_field form=$form name="success_url" value="{url path="/admin/document/type/{$documentType}/{$ID}/update"}"}
{admin_form_field form=$form name="locale" value="$edit_language_locale"}
{render_form_field form=$form field="success_url" value="{url path="/admin/document/type/{$documentType}/{$ID}/update"}"}
{render_form_field form=$form field="locale" value="$edit_language_locale"}
{if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}
@@ -57,15 +57,15 @@
</div>
<div class="col-md-6">
{admin_form_field form=$form name="file"}
{admin_form_field form=$form name="title" value=$TITLE}
{admin_form_field form=$form name="chapo" value=$CHAPO}
{admin_form_field form=$form name="postscriptum" value=$POSTSCRIPTUM}
{render_form_field form=$form field="file"}
{render_form_field form=$form field="title" value=$TITLE}
{render_form_field form=$form field="chapo" value=$CHAPO}
{render_form_field form=$form field="postscriptum" value=$POSTSCRIPTUM}
</div>
</div>
<div class="row">
<div class="col-md-12">
{admin_form_field form=$form name="description" value=$DESCRIPTION extra_class="wysiwyg"}
{render_form_field form=$form field="description" value=$DESCRIPTION extra_class="wysiwyg"}
</div>
</div>

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>

View File

@@ -40,8 +40,8 @@
{form_hidden_fields form=$form}
{admin_form_field form=$form name="success_url" value="{url path="/admin/image/type/{$imageType}/{$ID}/update"}"}
{admin_form_field form=$form name="locale" value="$edit_language_locale"}
{render_form_field form=$form field="success_url" value="{url path="/admin/image/type/{$imageType}/{$ID}/update"}"}
{render_form_field form=$form field="locale" value="$edit_language_locale"}
{if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}
@@ -60,15 +60,15 @@
</div>
<div class="col-md-6">
{admin_form_field form=$form name="file"}
{admin_form_field form=$form name="title" value=$TITLE}
{admin_form_field form=$form name="chapo" value=$CHAPO}
{admin_form_field form=$form name="postscriptum" value=$POSTSCRIPTUM}
{render_form_field form=$form field="file"}
{render_form_field form=$form field="title" value=$TITLE}
{render_form_field form=$form field="chapo" value=$CHAPO}
{render_form_field form=$form field="postscriptum" value=$POSTSCRIPTUM}
</div>
</div>
<div class="row">
<div class="col-md-12">
{admin_form_field form=$form name="description" value=$DESCRIPTION extra_class="wysiwyg"}
{render_form_field form=$form field="description" value=$DESCRIPTION extra_class="wysiwyg"}
</div>
</div>

View File

@@ -71,24 +71,15 @@
</div>
{/form_field}
{form_field form=$form field='brand_id'}
<div class="form-group {if $error}has-error{/if}">
{custom_render_form_field form=$form field='brand_id'}
<select {$field_attributes}>
<option value="0">{intl l="No brand"}</option>
{admin_form_field_label form=$form name='brand_id'}
<select id="{$label_attr.for}" {if $required}aria-required="true" required{/if} name="{$name}" class="form-control">
<option value="0">{intl l="No brand"}</option>
{loop name="brand-list" type="brand" visible="*"}
<option value="{$ID}" {if $BRAND_ID == $ID}selected="selected"{/if}>{$TITLE}</option>
{/loop}
</select>
{if ! empty($label_attr.help)}
<span class="help-block">{$label_attr.help}</span>
{/if}
</div>
{/form_field}
{loop name="brand-list" type="brand" visible="*"}
<option value="{$ID}" {if $BRAND_ID == $ID}selected="selected"{/if}>{$TITLE}</option>
{/loop}
</select>
{/custom_render_form_field}
{form_field form=$form field='visible'}
<div class="form-group {if $error}has-error{/if}">

View File

@@ -16,26 +16,21 @@
{form_hidden_fields form=$form}
{admin_form_field form=$form name="success_url"}
{render_form_field form=$form field="success_url"}
{* Display error message if exist *}
{include file='includes/notifications.html' message=$form_error_message}
{form_field form=$form field='url'}
<div class="form-group {if $error}has-error{/if}">
{admin_form_field_label form=$form name='url'}
<div class="input-group">
<span class="input-group-addon">{$url_language|default:{config key="url_site"}}/</span>
<input type="text" id="{$label_attr.for}" name="{$name}" value="{$value}" title="{$label}" {if $required} aria-required="true" required{/if} class="form-control" placeholder="{$label_attr.placeholder}">
</div>
{custom_render_form_field form=$form field='url'}
<div class="input-group">
<span class="input-group-addon">{$url_language|default:{config key="url_site"}}/</span>
<input type="text" id="{$label_attr.for}" name="{$name}" value="{$value}" title="{$label}" {if $required} aria-required="true" required{/if} class="form-control" placeholder="{$label_attr.placeholder}">
</div>
{/form_field}
{/custom_render_form_field}
{admin_form_field form=$form name="meta_title"}
{admin_form_field form=$form name="meta_description"}
{admin_form_field form=$form name="meta_keywords"}
{render_form_field form=$form field="meta_title"}
{render_form_field form=$form field="meta_description"}
{render_form_field form=$form field="meta_keywords"}
{include
file = "includes/inner-form-toolbar.html"

View File

@@ -1,6 +1,6 @@
{* The standard description fields, used by many Thelia objects *}
{admin_form_field form=$form name='title'}
{admin_form_field form=$form name="chapo"}
{admin_form_field form=$form name="description" extra_class="wysiwyg"}
{admin_form_field form=$form name="postscriptum"}
{render_form_field form=$form field='title'}
{render_form_field form=$form field="chapo"}
{render_form_field form=$form field="description" extra_class="wysiwyg"}
{render_form_field form=$form field="postscriptum"}