Required fields are now automatic from model validation

Make required asterisk more obvious
This commit is contained in:
Sam Georges 2014-07-12 16:56:26 +10:00
parent 9ae7b5785b
commit 62df6948b0
5 changed files with 11 additions and 3 deletions

View File

@ -3,6 +3,7 @@
- Added new properties to RelationController: readOnly, showSorting, defaultSort. - Added new properties to RelationController: readOnly, showSorting, defaultSort.
- Hashable, Sluggable, Purgeable and Validation traits must now be used in the Model class definition. - 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. - 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) * **Build 116** (2014-07-07)
- Added new layout and page method `onInit()` called after components are initialized and before AJAX requests are processed. - Added new layout and page method `onInit()` called after components are initialized and before AJAX requests are processed.

View File

@ -8159,8 +8159,9 @@ label {
.form-group.is-required > label:after { .form-group.is-required > label:after {
color: #ff0000; color: #ff0000;
vertical-align: super; vertical-align: super;
font-size: 50%; font-size: 60%;
content: " *"; content: " *";
text-shadow: 0 0 2px #b30000;
} }
.form-group.span-full { .form-group.span-full {
width: 100%; width: 100%;

View File

@ -99,8 +99,9 @@ label {
> label:after { > label:after {
color: @color-form-required-asterisk; color: @color-form-required-asterisk;
vertical-align: super; vertical-align: super;
font-size: 50%; font-size: 60%;
content: " *"; content: " *";
text-shadow: 0 0 2px darken(@color-form-required-asterisk, 15%);
} }
} }

View File

@ -487,6 +487,12 @@ class Form extends WidgetBase
*/ */
$field->value = $this->getFieldValue($field); $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 * Get field options from model
*/ */

View File

@ -7,7 +7,6 @@
<?php if ($field->label): ?> <?php if ($field->label): ?>
<label for="<?= $field->getId() ?>"> <label for="<?= $field->getId() ?>">
<?= e(trans($field->label)) ?> <?= e(trans($field->label)) ?>
<?= ($field->required ? '*' : '') ?>
</label> </label>
<?php endif ?> <?php endif ?>