From e9ef2a03aa78c12a7dfde00133382b88fce3868b Mon Sep 17 00:00:00 2001 From: David Craig Date: Fri, 21 Aug 2015 15:21:33 +1200 Subject: [PATCH] Consistant treatment of field's right title --- .../EditableCheckbox.php | 6 +++++- .../EditableCountryDropdownField.php | 6 +++++- .../editableformfields/EditableDateField.php | 9 +++++++-- .../editableformfields/EditableDropdown.php | 4 +++- .../editableformfields/EditableEmailField.php | 6 +++++- .../editableformfields/EditableFieldGroup.php | 3 ++- .../editableformfields/EditableFileField.php | 4 +++- .../editableformfields/EditableFormHeading.php | 3 +-- .../editableformfields/EditableFormStep.php | 2 +- .../editableformfields/EditableLiteralField.php | 3 +-- .../editableformfields/EditableNumericField.php | 8 ++++++-- .../editableformfields/EditableTextField.php | 12 +++++++++--- css/UserForm.css | 16 +++++++++++++++- scss/UserForm.scss | 16 +++++++++++++++- templates/UserFormsDropdownField.ss | 5 +++++ templates/UserFormsField.ss | 1 + templates/UserFormsField_holder.ss | 8 ++++++++ templates/UserFormsFileField.ss | 2 ++ templates/UserFormsGroupField_holder.ss | 10 ++-------- templates/UserFormsMultipleOptionField_holder.ss | 11 ++--------- templates/UserFormsTextareaField.ss | 1 + templates/UserformsCheckboxField.ss | 2 ++ templates/UserformsCheckboxField_holder.ss | 7 +++++++ 23 files changed, 108 insertions(+), 37 deletions(-) rename code/model/{formfields => editableformfields}/EditableCheckbox.php (90%) create mode 100644 templates/UserFormsDropdownField.ss create mode 100644 templates/UserFormsField.ss create mode 100644 templates/UserFormsField_holder.ss create mode 100644 templates/UserFormsFileField.ss create mode 100644 templates/UserFormsTextareaField.ss create mode 100644 templates/UserformsCheckboxField.ss create mode 100644 templates/UserformsCheckboxField_holder.ss diff --git a/code/model/formfields/EditableCheckbox.php b/code/model/editableformfields/EditableCheckbox.php similarity index 90% rename from code/model/formfields/EditableCheckbox.php rename to code/model/editableformfields/EditableCheckbox.php index e1e0bbc..31b504b 100755 --- a/code/model/formfields/EditableCheckbox.php +++ b/code/model/editableformfields/EditableCheckbox.php @@ -32,8 +32,12 @@ class EditableCheckbox extends EditableFormField { } public function getFormField() { - $field = CheckboxField::create($this->Name, $this->EscapedTitle, $this->CheckedDefault); + $field = CheckboxField::create($this->Name, $this->EscapedTitle, $this->CheckedDefault) + ->setFieldHolderTemplate('UserFormsCheckboxField_holder') + ->setTemplate('UserFormsCheckboxField'); + $this->doUpdateFormField($field); + return $field; } diff --git a/code/model/editableformfields/EditableCountryDropdownField.php b/code/model/editableformfields/EditableCountryDropdownField.php index 741f51b..e3c68f6 100644 --- a/code/model/editableformfields/EditableCountryDropdownField.php +++ b/code/model/editableformfields/EditableCountryDropdownField.php @@ -23,8 +23,12 @@ class EditableCountryDropdownField extends EditableFormField { } public function getFormField() { - $field = CountryDropdownField::create($this->Name, $this->EscapedTitle); + $field = CountryDropdownField::create($this->Name, $this->EscapedTitle) + ->setFieldHolderTemplate('UserFormsField_holder') + ->setTemplate('UserFormsDropdownField'); + $this->doUpdateFormField($field); + return $field; } diff --git a/code/model/editableformfields/EditableDateField.php b/code/model/editableformfields/EditableDateField.php index c16ab87..e0a81e6 100755 --- a/code/model/editableformfields/EditableDateField.php +++ b/code/model/editableformfields/EditableDateField.php @@ -43,9 +43,14 @@ class EditableDateField extends EditableFormField { $defaultValue = $this->DefaultToToday ? SS_Datetime::now()->Format('Y-m-d') : $this->Default; - $field = EditableDateField_FormField::create( $this->Name, $this->EscapedTitle, $defaultValue); - $field->setConfig('showcalendar', true); + + $field = EditableDateField_FormField::create( $this->Name, $this->EscapedTitle, $defaultValue) + ->setConfig('showcalendar', true) + ->setFieldHolderTemplate('UserFormsField_holder') + ->setTemplate('UserFormsField'); + $this->doUpdateFormField($field); + return $field; } } diff --git a/code/model/editableformfields/EditableDropdown.php b/code/model/editableformfields/EditableDropdown.php index a8d6ad4..8ebb72c 100755 --- a/code/model/editableformfields/EditableDropdown.php +++ b/code/model/editableformfields/EditableDropdown.php @@ -28,7 +28,9 @@ class EditableDropdown extends EditableMultipleOptionField { * @return DropdownField */ public function getFormField() { - $field = DropdownField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap()); + $field = DropdownField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap()) + ->setFieldHolderTemplate('UserFormsField_holder') + ->setTemplate('UserFormsDropdownField'); // Set default $defaultOption = $this->getDefaultOptions()->first(); diff --git a/code/model/editableformfields/EditableEmailField.php b/code/model/editableformfields/EditableEmailField.php index 8f9eb9c..ac2a2d6 100755 --- a/code/model/editableformfields/EditableEmailField.php +++ b/code/model/editableformfields/EditableEmailField.php @@ -18,8 +18,12 @@ class EditableEmailField extends EditableFormField { } public function getFormField() { - $field = EmailField::create($this->Name, $this->EscapedTitle, $this->Default); + $field = EmailField::create($this->Name, $this->EscapedTitle, $this->Default) + ->setFieldHolderTemplate('UserFormsField_holder') + ->setTemplate('UserFormsField'); + $this->doUpdateFormField($field); + return $field; } diff --git a/code/model/editableformfields/EditableFieldGroup.php b/code/model/editableformfields/EditableFieldGroup.php index 55d8d0c..6e2ca52 100644 --- a/code/model/editableformfields/EditableFieldGroup.php +++ b/code/model/editableformfields/EditableFieldGroup.php @@ -54,7 +54,8 @@ class EditableFieldGroup extends EditableFormField { public function getFormField() { $field = UserFormsGroupField::create() - ->setTitle($this->EscapedTitle ?: false); + ->setTitle($this->EscapedTitle ?: false) + ->setName($this->Name); $this->doUpdateFormField($field); return $field; } diff --git a/code/model/editableformfields/EditableFileField.php b/code/model/editableformfields/EditableFileField.php index 5cff5a2..6e66acc 100755 --- a/code/model/editableformfields/EditableFileField.php +++ b/code/model/editableformfields/EditableFileField.php @@ -35,7 +35,9 @@ class EditableFileField extends EditableFormField { } public function getFormField() { - $field = FileField::create($this->Name, $this->EscapedTitle); + $field = FileField::create($this->Name, $this->EscapedTitle) + ->setFieldHolderTemplate('UserFormsField_holder') + ->setTemplate('UserFormsFileField'); // filter out '' since this would be a regex problem on JS end $field->getValidator()->setAllowedExtensions( diff --git a/code/model/editableformfields/EditableFormHeading.php b/code/model/editableformfields/EditableFormHeading.php index c3274e2..87bf6d7 100755 --- a/code/model/editableformfields/EditableFormHeading.php +++ b/code/model/editableformfields/EditableFormHeading.php @@ -29,8 +29,7 @@ class EditableFormHeading extends EditableFormField { public function getCMSFields() { $fields = parent::getCMSFields(); - $fields->removeByName('Default'); - $fields->removeByName('Validation'); + $fields->removeByName(array('Default', 'Validation', 'RightTitle')); $levels = array( '1' => '1', diff --git a/code/model/editableformfields/EditableFormStep.php b/code/model/editableformfields/EditableFormStep.php index 294f6b2..acc7bab 100644 --- a/code/model/editableformfields/EditableFormStep.php +++ b/code/model/editableformfields/EditableFormStep.php @@ -24,7 +24,7 @@ class EditableFormStep extends EditableFormField { public function getCMSFields() { $fields = parent::getCMSFields(); - $fields->removeByName(array('MergeField', 'Default', 'Validation')); + $fields->removeByName(array('MergeField', 'Default', 'Validation', 'RightTitle')); return $fields; } diff --git a/code/model/editableformfields/EditableLiteralField.php b/code/model/editableformfields/EditableLiteralField.php index 109d4a9..dcc82da 100644 --- a/code/model/editableformfields/EditableLiteralField.php +++ b/code/model/editableformfields/EditableLiteralField.php @@ -94,8 +94,7 @@ class EditableLiteralField extends EditableFormField { public function getCMSFields() { $fields = parent::getCMSFields(); - $fields->removeByName('Default'); - $fields->removeByName('Validation'); + $fields->removeByName(array('Default', 'Validation', 'RightTitle')); $fields->addFieldsToTab('Root.Main', array( HTMLEditorField::create('Content', _t('EditableLiteralField.CONTENT', 'HTML')) diff --git a/code/model/editableformfields/EditableNumericField.php b/code/model/editableformfields/EditableNumericField.php index 70f0bef..742bbbe 100755 --- a/code/model/editableformfields/EditableNumericField.php +++ b/code/model/editableformfields/EditableNumericField.php @@ -26,9 +26,13 @@ class EditableNumericField extends EditableFormField { * @return NumericField */ public function getFormField() { - $field = new NumericField($this->Name, $this->EscapedTitle, $this->Default); - $field->addExtraClass('number'); + $field = NumericField::create($this->Name, $this->EscapedTitle, $this->Default) + ->setFieldHolderTemplate('UserFormsField_holder') + ->setTemplate('UserFormsField') + ->addExtraClass('number'); + $this->doUpdateFormField($field); + return $field; } diff --git a/code/model/editableformfields/EditableTextField.php b/code/model/editableformfields/EditableTextField.php index 4d21438..384aeae 100755 --- a/code/model/editableformfields/EditableTextField.php +++ b/code/model/editableformfields/EditableTextField.php @@ -65,12 +65,18 @@ class EditableTextField extends EditableFormField { */ public function getFormField() { if($this->Rows > 1) { - $field = TextareaField::create($this->Name, $this->EscapedTitle, $this->Default); - $field->setRows($this->Rows); + $field = TextareaField::create($this->Name, $this->EscapedTitle, $this->Default) + ->setFieldHolderTemplate('UserFormsField_holder') + ->setTemplate('UserFormsTextareaField') + ->setRows($this->Rows); } else { - $field = TextField::create($this->Name, $this->EscapedTitle, $this->Default, $this->MaxLength); + $field = TextField::create($this->Name, $this->EscapedTitle, $this->Default, $this->MaxLength) + ->setFieldHolderTemplate('UserFormsField_holder') + ->setTemplate('UserFormsField'); } + $this->doUpdateFormField($field); + return $field; } diff --git a/css/UserForm.css b/css/UserForm.css index 62413bd..f796879 100644 --- a/css/UserForm.css +++ b/css/UserForm.css @@ -52,9 +52,23 @@ margin-top: 12px; margin-bottom: 12px; } -.userformsgroup legend { +.userformsgroup > legend { padding-left: 4px; padding-right: 4px; border: 0; width: auto; } + +.right-title { + clear: both; + display: block; +} + +.checkbox .right-title { + display: inline; +} + +.left { + margin-bottom: 5px; + font-weight: bold; +} diff --git a/scss/UserForm.scss b/scss/UserForm.scss index 3fa886e..35894c5 100644 --- a/scss/UserForm.scss +++ b/scss/UserForm.scss @@ -64,10 +64,24 @@ margin-top: 12px; margin-bottom: 12px; - legend { + > legend { padding-left: 4px; padding-right: 4px; border: 0; width: auto; } } + +.right-title { + clear: both; + display: block; +} + +.checkbox .right-title { + display: inline; +} + +.left { + margin-bottom: 5px; + font-weight: bold; +} diff --git a/templates/UserFormsDropdownField.ss b/templates/UserFormsDropdownField.ss new file mode 100644 index 0000000..14a1691 --- /dev/null +++ b/templates/UserFormsDropdownField.ss @@ -0,0 +1,5 @@ + diff --git a/templates/UserFormsField.ss b/templates/UserFormsField.ss new file mode 100644 index 0000000..51bfeac --- /dev/null +++ b/templates/UserFormsField.ss @@ -0,0 +1 @@ +aria-describedby="{$Name}_right_title" <% end_if %>/> diff --git a/templates/UserFormsField_holder.ss b/templates/UserFormsField_holder.ss new file mode 100644 index 0000000..9c0c6ff --- /dev/null +++ b/templates/UserFormsField_holder.ss @@ -0,0 +1,8 @@ +
+ <% if $Title %><% end_if %> +
+ $Field +
+ <% if $RightTitle %>$RightTitle<% end_if %> + <% if $Message %>$Message<% end_if %> +
diff --git a/templates/UserFormsFileField.ss b/templates/UserFormsFileField.ss new file mode 100644 index 0000000..736c0f0 --- /dev/null +++ b/templates/UserFormsFileField.ss @@ -0,0 +1,2 @@ + + aria-describedby="{$Name}_right_title"<% end_if %>/> diff --git a/templates/UserFormsGroupField_holder.ss b/templates/UserFormsGroupField_holder.ss index 52c2e84..0ab7a23 100644 --- a/templates/UserFormsGroupField_holder.ss +++ b/templates/UserFormsGroupField_holder.ss @@ -1,4 +1,4 @@ -<$Tag class="CompositeField $extraClass <% if ColumnCount %>multicolumn<% end_if %>"> +<$Tag class="CompositeField $extraClass <% if ColumnCount %>multicolumn<% end_if %>"<% if $Tag == 'fieldset' && $RightTitle %>aria-describedby="{$Name}_right_title"<% end_if %>> <% if $Tag == 'fieldset' && $Legend %> $Legend <% end_if %> @@ -15,11 +15,5 @@ <% end_loop %> - <% if $RightTitle %> - - <% end_if %> - - <% if $Description %>$Description<% end_if %> + <% if $RightTitle %>$RightTitle<% end_if %> diff --git a/templates/UserFormsMultipleOptionField_holder.ss b/templates/UserFormsMultipleOptionField_holder.ss index 9f90702..03483d3 100644 --- a/templates/UserFormsMultipleOptionField_holder.ss +++ b/templates/UserFormsMultipleOptionField_holder.ss @@ -1,17 +1,10 @@ -
+
aria-describedby="{$Name}_right_title"<% end_if %>> <% if $Title %>$Title<% end_if %>
$Field
- <% if $RightTitle %> - - <% end_if %> - + <% if $RightTitle %>$RightTitle<% end_if %> <% if $Message %>$Message<% end_if %> - - <% if $Description %>$Description<% end_if %>
diff --git a/templates/UserFormsTextareaField.ss b/templates/UserFormsTextareaField.ss new file mode 100644 index 0000000..b421bb5 --- /dev/null +++ b/templates/UserFormsTextareaField.ss @@ -0,0 +1 @@ + diff --git a/templates/UserformsCheckboxField.ss b/templates/UserformsCheckboxField.ss new file mode 100644 index 0000000..e758cc4 --- /dev/null +++ b/templates/UserformsCheckboxField.ss @@ -0,0 +1,2 @@ +aria-describedby="{$Name}_right_title" <% end_if %>/> +<% if $RightTitle %>$RightTitle<% end_if %> diff --git a/templates/UserformsCheckboxField_holder.ss b/templates/UserformsCheckboxField_holder.ss new file mode 100644 index 0000000..6754cca --- /dev/null +++ b/templates/UserformsCheckboxField_holder.ss @@ -0,0 +1,7 @@ +
+ <% if $Title %><% end_if %> +
+ $Field +
+ <% if $Message %>$Message<% end_if %> +