From 62df6948b0d3ce7ad217a4b5936e9d19b865e6b6 Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Sat, 12 Jul 2014 16:56:26 +1000 Subject: [PATCH] Required fields are now automatic from model validation Make required asterisk more obvious --- CHANGELOG.md | 1 + modules/backend/assets/css/october.css | 3 ++- modules/backend/assets/less/controls/forms.less | 3 ++- modules/backend/widgets/Form.php | 6 ++++++ modules/backend/widgets/form/partials/_field.htm | 1 - 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6a9c9ed9..89b837fef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Added new properties to RelationController: readOnly, showSorting, defaultSort. - Hashable, Sluggable, Purgeable and Validation traits must now be used in the Model class definition. - Plugins can now extend existing Back-end navigation menu items, see Event docs for an example. + - Required form fields now sport an asterisk (*) character at the end of their label. * **Build 116** (2014-07-07) - Added new layout and page method `onInit()` called after components are initialized and before AJAX requests are processed. diff --git a/modules/backend/assets/css/october.css b/modules/backend/assets/css/october.css index 4b41dcee0..b614c31f5 100644 --- a/modules/backend/assets/css/october.css +++ b/modules/backend/assets/css/october.css @@ -8159,8 +8159,9 @@ label { .form-group.is-required > label:after { color: #ff0000; vertical-align: super; - font-size: 50%; + font-size: 60%; content: " *"; + text-shadow: 0 0 2px #b30000; } .form-group.span-full { width: 100%; diff --git a/modules/backend/assets/less/controls/forms.less b/modules/backend/assets/less/controls/forms.less index 62875db49..4afe2ac04 100644 --- a/modules/backend/assets/less/controls/forms.less +++ b/modules/backend/assets/less/controls/forms.less @@ -99,8 +99,9 @@ label { > label:after { color: @color-form-required-asterisk; vertical-align: super; - font-size: 50%; + font-size: 60%; content: " *"; + text-shadow: 0 0 2px darken(@color-form-required-asterisk, 15%); } } diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 236e9ab20..44aaec537 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -487,6 +487,12 @@ class Form extends WidgetBase */ $field->value = $this->getFieldValue($field); + /* + * Check model if field is required + */ + if (!$field->required && $this->model && method_exists($this->model, 'isAttributeRequired')) + $field->required = $this->model->isAttributeRequired($field->columnName); + /* * Get field options from model */ diff --git a/modules/backend/widgets/form/partials/_field.htm b/modules/backend/widgets/form/partials/_field.htm index 901a4d364..b66aba0e2 100644 --- a/modules/backend/widgets/form/partials/_field.htm +++ b/modules/backend/widgets/form/partials/_field.htm @@ -7,7 +7,6 @@ label): ?>