From 7576b9990bb9794d381c6883b4ac074101f2cb4b Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 3 Jul 2014 16:54:42 +0200 Subject: [PATCH] Fixed minor typos, improved field attributes generation --- .../Form/StandardDescriptionFieldsTrait.php | 5 ++- ...rm-field-attributes-standard-renderer.html | 34 ++++++++++++++++--- .../forms/form-field-standard-renderer.html | 10 ------ 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php b/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php index 04fbbe033..2d3793f7c 100644 --- a/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php +++ b/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php @@ -49,11 +49,10 @@ trait StandardDescriptionFieldsTrait 'required' => true, 'label' => Translator::getInstance()->trans('Title'), 'label_attr' => [ - 'for' => 'title_field', - 'placeholder' => Translator::getInstance()->trans('A descriptive title') + 'for' => 'title_field' ], 'attr' => [ - + 'placeholder' => Translator::getInstance()->trans('A descriptive title') ] ] ); diff --git a/templates/backOffice/default/forms/form-field-attributes-standard-renderer.html b/templates/backOffice/default/forms/form-field-attributes-standard-renderer.html index e1558d982..d986e7a50 100644 --- a/templates/backOffice/default/forms/form-field-attributes-standard-renderer.html +++ b/templates/backOffice/default/forms/form-field-attributes-standard-renderer.html @@ -8,14 +8,40 @@ In addition to the standard form_field block output, this fragment uses the foll - field_extra_class : an extra class to add to the input class (see form-field-attributes-standard-renderer.html) *} +{* 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 $disabled} + {$disabled = 'disabled'} +{/if} + +{if $disabled} + {$readonly = 'readonly'} +{/if} + +{if $required} + {$required='aria-required="true" required'} +{/if} + +{if $attr_list.placeholder} + {$placeholder = "placeholder=\"{$attr_list.placeholder}\""} +{/if} + {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} + id="{$label_attr.for}" name="{$name}" class="{$field_extra_class}" value="{$value}" {if $checked}checked="checked"{/if} {$disabled} {$readonly} {$required} {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}" + id="{$label_attr.for}" name="{$name} "class="form-control class="{$field_extra_class}" {if $multiple}multiple{/if} {if $lattr_list.size}size="{$lattr_list.size}"{/if} {$disabled} {$readonly} {$required} {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}" + id="{$label_attr.for}" name="{$name}" class="form-control {$field_extra_class}" {if $attr_list.rows}rows="{$attr_list.rows}"{/if} {$placeholder nofilter} {$disabled} {$readonly} {$required} {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}" + id="{$label_attr.for}" name="{$name}" value="{$value}" class="form-control {$field_extra_class}" {$placeholder nofilter} {$disabled} {$readonly} {$required} {/if} diff --git a/templates/backOffice/default/forms/form-field-standard-renderer.html b/templates/backOffice/default/forms/form-field-standard-renderer.html index 5e338117d..654abff2f 100644 --- a/templates/backOffice/default/forms/form-field-standard-renderer.html +++ b/templates/backOffice/default/forms/form-field-standard-renderer.html @@ -9,16 +9,6 @@ fragment uses the following additional variables : 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"}