Skip to content

Commit

Permalink
form validation fixes (#300)
Browse files Browse the repository at this point in the history
* form validation fixes
  • Loading branch information
Dimitri Grammatikogianni authored and C-Lodder committed Jan 21, 2017
1 parent 8c7b09a commit f0ba73a
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 247 deletions.
5 changes: 4 additions & 1 deletion administrator/language/en-GB/en-GB.lib_joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,15 @@ JLIB_FORM_BUTTON_SELECT="Select"
JLIB_FORM_CHANGE_IMAGE="Change Image"
JLIB_FORM_CHANGE_IMAGE_BUTTON="Change Image Button"
JLIB_FORM_CHANGE_USER="Select User"
JLIB_FORM_CONTAINS_INVALID_FIELDS="The form cannot be submitted as it's missing required data. <br/> Please correct the marked fields and try again"
JLIB_FORM_ERROR_FIELDS_CATEGORY_ERROR_EXTENSION_EMPTY="Extension attribute is empty in the category field."
JLIB_FORM_ERROR_FIELDS_GROUPEDLIST_ELEMENT_NAME="Unknown element type: %s"
JLIB_FORM_ERROR_NO_DATA="No data."
JLIB_FORM_ERROR_VALIDATE_FIELD="Invalid xml field."
JLIB_FORM_ERROR_XML_FILE_DID_NOT_LOAD="XML file did not load."
JLIB_FORM_FIELD_INVALID="Invalid field:&#160"
JLIB_FORM_FIELD_REQUIRED_CHECK="One of the options must be selected"
JLIB_FORM_FIELD_REQUIRED_VALUE="Field value cannot be empty"
JLIB_FORM_INPUTMODE="latin"
JLIB_FORM_INVALID_FORM_OBJECT="Invalid Form Object: :%s"
JLIB_FORM_INVALID_FORM_RULE="Invalid Form Rule: :%s"
Expand Down Expand Up @@ -338,7 +341,7 @@ JLIB_FORM_VALUE_SESSION_XCACHE="XCache"
JLIB_FORM_VALUE_TIMEZONE_UTC="Universal Time, Coordinated (UTC)"
JLIB_FORM_VALUE_FROM_TEMPLATE="From Template"
JLIB_FORM_VALUE_INHERITED="Inherited"

JLIB_FORM_FIELD_INVALID_VALUE="This value is not valid"
JLIB_HTML_ACCESS_MODIFY_DESC_CAPTION_ACL="ACL"
JLIB_HTML_ACCESS_MODIFY_DESC_CAPTION_TABLE="Table"
JLIB_HTML_ACCESS_SUMMARY_DESC_CAPTION="ACL Summary Table"
Expand Down
14 changes: 14 additions & 0 deletions administrator/templates/atum/css/template.css
Original file line number Diff line number Diff line change
Expand Up @@ -8882,10 +8882,24 @@ legend {
.modal label {
width: 100%; }

.invalid {
border-color: #bc6564;
color: #bc6564; }

.valid {
border-color: #64bd63; }

.custom-select[multiple] {
height: auto;
background: none; }

.invalid {
border-color: #bc6564;
color: #bc6564; }

.valid {
border-color: #64bd63; }

.header {
position: relative;
z-index: 5;
Expand Down
2 changes: 1 addition & 1 deletion administrator/templates/atum/css/template.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion administrator/templates/atum/css/template.min.css

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions administrator/templates/atum/scss/blocks/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,27 @@ legend {
width: 100%;
}

// Validation
.invalid {
border-color: $switcher-color-danger;
color: $switcher-color-danger;
}
.valid {
border-color: $switcher-color-success;
}

// Possibly temporary until Bootstrap suport it themselves
.custom-select[multiple] {
height: auto;
background: none;
}

// Validation
.invalid {
border-color: $switcher-color-danger;
color: $switcher-color-danger;
}

.valid {
border-color: $switcher-color-success;
}
5 changes: 4 additions & 1 deletion language/en-GB/en-GB.lib_joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,16 @@ JLIB_FORM_BUTTON_SELECT="Select"
JLIB_FORM_CHANGE_IMAGE="Change Image"
JLIB_FORM_CHANGE_IMAGE_BUTTON="Change Image Button"
JLIB_FORM_CHANGE_USER="Select User"
JLIB_FORM_CONTAINS_INVALID_FIELDS="The form cannot be submitted as it's missing required data. <br/> Please correct the marked fields and try again"
JLIB_FORM_ERROR_FIELDS_CATEGORY_ERROR_EXTENSION_EMPTY="Extension attribute is empty in the category field."
JLIB_FORM_ERROR_FIELDS_GROUPEDLIST_ELEMENT_NAME="Unknown element type: %s"
JLIB_FORM_ERROR_NO_DATA="No data."
JLIB_FORM_ERROR_VALIDATE_FIELD="Invalid xml field."
JLIB_FORM_ERROR_XML_FILE_DID_NOT_LOAD="XML file did not load."
JLIB_FORM_FIELD_INVALID="Invalid field:&#160"
JLIB_FORM_INPUTMODE="latin"
JLIB_FORM_FIELD_INVALID_VALUE="This value is not valid"
JLIB_FORM_FIELD_REQUIRED_CHECK="One of the options must be selected"
JLIB_FORM_FIELD_REQUIRED_VALUE="Field value cannot be empty"JLIB_FORM_INPUTMODE="latin"
JLIB_FORM_INVALID_FORM_OBJECT="Invalid Form Object: :%s"
JLIB_FORM_INVALID_FORM_RULE="Invalid Form Rule: :%s"
JLIB_FORM_MEDIA_PREVIEW_ALT="Selected image."
Expand Down
3 changes: 3 additions & 0 deletions layouts/joomla/form/field/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
$spellcheck ? '' : 'spellcheck="false"',
!empty($inputmode) ? 'inputmode="' . $inputmode . '"' : '',
!empty($pattern) ? 'pattern="' . $pattern . '"' : '',

// @TODO add a proper string here!!!
!empty($validationtext) ? 'data-validation-text="' . $validationtext . '"' : '',
);
?>
<input type="text" name="<?php
Expand Down
5 changes: 4 additions & 1 deletion libraries/cms/html/behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ public static function formvalidator()
static::core();

// Add validate.js language strings
JText::script('JLIB_FORM_FIELD_INVALID');
JText::script('JLIB_FORM_CONTAINS_INVALID_FIELDS');
JText::script('JLIB_FORM_FIELD_REQUIRED_VALUE');
JText::script('JLIB_FORM_FIELD_REQUIRED_CHECK');
JText::script('JLIB_FORM_FIELD_INVALID_VALUE');

JHtml::_('script', 'vendor/punycode/punycode.js', array('version' => 'auto', 'relative' => true));
JHtml::_('script', 'system/fields/validate.min.js', array('version' => 'auto', 'relative' => true));
Expand Down
61 changes: 36 additions & 25 deletions libraries/joomla/form/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ abstract class JFormField
*/
protected $pattern;

/**
* The validation text of invalid value of the form field.
*
* @var string
* @since 4.0
*/
protected $validationtext;

/**
* The name of the form field.
*
Expand Down Expand Up @@ -404,6 +412,7 @@ public function __get($name)
case 'autofocus':
case 'autocomplete':
case 'spellcheck':
case 'validationtext':
case 'showon':
return $this->$name;

Expand Down Expand Up @@ -459,6 +468,7 @@ public function __set($name, $value)
case 'onclick':
case 'validate':
case 'pattern':
case 'validationtext':
case 'group':
case 'showon':
case 'default':
Expand Down Expand Up @@ -581,7 +591,7 @@ public function setup(SimpleXMLElement $element, $value, $group = null)
$this->group = $group;

$attributes = array(
'multiple', 'name', 'id', 'hint', 'class', 'description', 'labelclass', 'onchange', 'onclick', 'validate', 'pattern', 'default',
'multiple', 'name', 'id', 'hint', 'class', 'description', 'labelclass', 'onchange', 'onclick', 'validate', 'pattern', 'validationtext', 'default',
'required', 'disabled', 'readonly', 'autofocus', 'hidden', 'autocomplete', 'spellcheck', 'translateHint', 'translateLabel',
'translate_label', 'translateDescription', 'translate_description', 'size', 'showon');

Expand Down Expand Up @@ -986,30 +996,31 @@ protected function getLayoutData()
$alt = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname);

return array(
'autocomplete' => $this->autocomplete,
'autofocus' => $this->autofocus,
'class' => $this->class,
'description' => $description,
'disabled' => $this->disabled,
'field' => $this,
'group' => $this->group,
'hidden' => $this->hidden,
'hint' => $this->translateHint ? JText::alt($this->hint, $alt) : $this->hint,
'id' => $this->id,
'label' => $label,
'labelclass' => $this->labelclass,
'multiple' => $this->multiple,
'name' => $this->name,
'onchange' => $this->onchange,
'onclick' => $this->onclick,
'pattern' => $this->pattern,
'readonly' => $this->readonly,
'repeat' => $this->repeat,
'required' => (bool) $this->required,
'size' => $this->size,
'spellcheck' => $this->spellcheck,
'validate' => $this->validate,
'value' => $this->value,
'autocomplete' => $this->autocomplete,
'autofocus' => $this->autofocus,
'class' => $this->class,
'description' => $description,
'disabled' => $this->disabled,
'field' => $this,
'group' => $this->group,
'hidden' => $this->hidden,
'hint' => $this->translateHint ? JText::alt($this->hint, $alt) : $this->hint,
'id' => $this->id,
'label' => $label,
'labelclass' => $this->labelclass,
'multiple' => $this->multiple,
'name' => $this->name,
'onchange' => $this->onchange,
'onclick' => $this->onclick,
'pattern' => $this->pattern,
'validationtext' => $this->validationtext,
'readonly' => $this->readonly,
'repeat' => $this->repeat,
'required' => (bool) $this->required,
'size' => $this->size,
'spellcheck' => $this->spellcheck,
'validate' => $this->validate,
'value' => $this->value,
);
}

Expand Down
Loading

0 comments on commit f0ba73a

Please sign in to comment.