Commit 372993e5 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Added validator.js attributes 'data-pattern-error', 'data-rquired-error',...

Added validator.js attributes 'data-pattern-error', 'data-rquired-error', 'data-match-error', 'data-error' to be specified in config.qfq.ini, Form or FormElement. Detailed setting will overwrite generic setting. If none is specified, take validator.js defaults.

HelperFormElement.php, AbstractBuildForm.php, Constants.php, QuickFormQuery.php.
parent c7b6e204
......@@ -126,6 +126,16 @@ config.qfq.ini
+-------------------------+-----------------------------------------+----------------------------------------------------------------------------+
| DATE_FORMAT | DATE_FORMAT= yyyy-mm-dd | Possible options: yyyy-mm-dd, dd.mm.yyyy |
+-------------------------+-----------------------------------------+----------------------------------------------------------------------------+
| FORM_DATA_PATTERN_ERROR |FORM_DATA_PATTERN_ERROR=please check pa. | Customizable error message used in validator.js. 'pattern' violation |
+-------------------------+-----------------------------------------+----------------------------------------------------------------------------+
| FORM_DATA_REQUIRED_ERROR|FORM_DATA_REQUIRED_ERROR=missing value | Customizable error message used in validator.js. 'required' fields |
+-------------------------+-----------------------------------------+----------------------------------------------------------------------------+
| FORM_DATA_MATCH_ERROR |FORM_DATA_MATCH_ERROR=type error | Customizable error message used in validator.js. 'match' retype mismatch |
+-------------------------+-----------------------------------------+----------------------------------------------------------------------------+
| FORM_DATA_ERROR |FORM_DATA_ERROR=generic error | Customizable error message used in validator.js. 'no specific' given |
+-------------------------+-----------------------------------------+----------------------------------------------------------------------------+
Example: *typo3conf/config.qfq.ini*
......
......@@ -559,6 +559,14 @@ parameter
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
| extraDeleteForm | string | Name of a form which specifies how to delete the primary record and optional slave records |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
| data-pattern-error | string | Pattern violation: Text for error message used for all FormElements of current form |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
| data-required-error | string | Required violation: Text for error message used for all FormElements of current form |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
| data-match-error | string | Match violation: Text for error message used for all FormElements of current form |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
| data-error | string | If none specific is defined: Text for error message used for all FormElements of current form |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
* Example:
......@@ -762,6 +770,19 @@ Fields:
|created | datetime |set once through QFQ |
+---------------+-----------------------------+---------------------------------------------------------------------------------------------------+
Attributes defined in the parameter field:
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
| data-pattern-error | string | Pattern violation: Text for error message used for all FormElements of current form |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
| data-required-error | string | Required violation: Text for error message used for all FormElements of current form |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
| data-match-error | string | Match violation: Text for error message used for all FormElements of current form |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
| data-error | string | If none specific is defined: Text for error message used for all FormElements of current form |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
Implications
+------------------+----------+---------+-------------+----------+--------+-------+------+----------+-------+--------+-----------+---------+--------+--------+
......@@ -844,6 +865,7 @@ Implications
| accept | | | | | | | | | | | | | - 3 | |
+------------------+----------+---------+-------------+----------+--------+-------+------+----------+-------+--------+-----------+---------+--------+--------+
* 1: A line break created every <size> elements. Easy way to make checkboxes or radio vertical instead of horizontal.
* 2: Any number >1 makes the 'select' input 'multiple' ready.
* See: https://www.w3.org/TR/html5/forms.html#file-upload-state-(type=file)
......
......@@ -30,3 +30,9 @@ CSS_CLASS_QFQ_FORM_BODY = qfq-color-grey-2
; yyyy-mm-dd, dd.mm.yyyy
DATE_FORMAT = yyyy-mm-dd
; validator.js: data-pattern-error="", data-required-error="", data-match-error="", data-error=""
FORM_DATA_PATTERN_ERROR =
FORM_DATA_REQUIRED_ERROR =
FORM_DATA_MATCH_ERROR =
FORM_DATA_ERROR =
......@@ -669,11 +669,6 @@ abstract class AbstractBuildForm {
$attribute = Support::doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('class', 'form-control');
// if (isset($formElement[FE_RETYPE]) && $formElement[FE_RETYPE] == '1') {
// $htmlFormElementIdRetype = str_replace($formElement[FE_NAME], $formElement[FE_NAME] . RETYPE_FE_NAME_EXTENSION, $htmlFormElementId);
// $attribute .= Support::doAttribute('data-compare-element', $htmlFormElementIdRetype);
// }
if (isset($formElement[FE_RETYPE_SOURCE_NAME])) {
$htmlFormElementIdPrimary = str_replace(RETYPE_FE_NAME_EXTENSION, '', $htmlFormElementId);
$attribute .= Support::doAttribute('data-match', '[name=' . str_replace(':', '\\:', $htmlFormElementIdPrimary) . ']');
......@@ -705,6 +700,7 @@ abstract class AbstractBuildForm {
}
$attribute .= $this->getAttributeList($formElement, ['autocomplete', 'autofocus', 'placeholder']);
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$attribute .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('title', $formElement['tooltip']);
$attribute .= $this->getInputCheckPattern($formElement['checkType'], $formElement['checkPattern']);
......@@ -824,13 +820,14 @@ abstract class AbstractBuildForm {
*
* @param array $formElement
* @param array $attributeList
* @param bool $flagOmitEmpty
* @return string
*/
private function getAttributeList(array $formElement, array $attributeList) {
private function getAttributeList(array $formElement, array $attributeList, $flagOmitEmpty = true) {
$attribute = '';
foreach ($attributeList as $item) {
if (isset($formElement[$item]))
$attribute .= Support::doAttribute(strtolower($item), $formElement[$item]);
$attribute .= Support::doAttribute(strtolower($item), $formElement[$item], $flagOmitEmpty);
}
return $attribute;
}
......
......@@ -298,6 +298,13 @@ const SYSTEM_CSS_CLASS_QFQ_CONTAINER = 'CSS_CLASS_QFQ_CONTAINER';
const SYSTEM_CSS_CLASS_QFQ_FORM_PILL = 'CSS_CLASS_QFQ_FORM_PILL';
const SYSTEM_CSS_CLASS_QFQ_FORM_BODY = 'CSS_CLASS_QFQ_FORM_BODY';
// Textmessages used for Form validation.
const SYSTEM_FORM_DATA_PATTERN_ERROR = 'FORM_DATA_PATTERN_ERROR';
const SYSTEM_FORM_DATA_REQUIRED_ERROR = 'FORM_DATA_REQUIRED_ERROR';
const SYSTEM_FORM_DATA_MATCH_ERROR = 'FORM_DATA_MATCH_ERROR';
const SYSTEM_FORM_DATA_ERROR = 'FORM_DATA_ERROR';
// computed automatically during runtime
const SYSTEM_PATH_EXT = 'EXT_PATH';
const SYSTEM_SITE_PATH = 'SITE_PATH';
......@@ -455,6 +462,12 @@ const F_SUBMIT_BUTTON_TEXT = 'submitButtonText';
const F_CLASS_PILL = 'classPill';
const F_CLASS_BODY = 'classBody';
const F_FE_DATA_PATTERN_ERROR = 'data-pattern-error';
const F_FE_DATA_REQUIRED_ERROR = 'data-required-error';
const F_FE_DATA_MATCH_ERROR = 'data-match-error';
const F_FE_DATA_ERROR = 'data-error';
// FORM_ELEMENT_STATI
const FE_MODE_SHOW = 'show';
const FE_MODE_READONLY = 'readonly';
......
......@@ -378,39 +378,22 @@ class QuickFormQuery {
$form = $this->db->sql("SELECT * FROM Form AS f WHERE f." . F_NAME . " LIKE ? AND f.deleted='no'", ROW_EXPECT_1,
[$formName], 'Form not found or multiple forms with the same name.');
$form = $this->modeAdjustFormConfig($mode, $form);
$form = $this->modeCleanFormConfig($mode, $form);
$this->formSpec = $this->eval->parseArray($form);
HelperFormElement::explodeParameter($this->formSpec);
$formSpec = $this->eval->parseArray($form);
HelperFormElement::explodeParameter($formSpec);
# Set defaults:
Support::setIfNotSet($this->formSpec, 'class', '');
Support::setIfNotSet($this->formSpec, F_BS_LABEL_COLUMNS, 3, '');
Support::setIfNotSet($this->formSpec, F_BS_INPUT_COLUMNS, 6, '');
Support::setIfNotSet($this->formSpec, F_BS_NOTE_COLUMNS, 3, '');
Support::setIfNotSet($this->formSpec, F_SUBMIT_BUTTON_TEXT, '');
Support::setIfNotSet($this->formSpec, F_EXTRA_DELETE_FORM, '');
$formSpec = $this->setFormDefault($formSpec);
// Set F_FINAL_DELETE_FORM
$this->formSpec[F_FINAL_DELETE_FORM] = $this->formSpec[F_EXTRA_DELETE_FORM] != '' ? $this->formSpec[F_EXTRA_DELETE_FORM] : $this->formSpec[F_NAME];
$formSpec[F_FINAL_DELETE_FORM] = ($formSpec[F_EXTRA_DELETE_FORM] != '') ? $formSpec[F_EXTRA_DELETE_FORM] : $formSpec[F_NAME];
// Take default from config.ini
$class = $this->store->getVar(SYSTEM_CSS_CLASS_QFQ_FORM_PILL, STORE_SYSTEM);
$class = $class ? $class : 'qfq-color-grey-1';
Support::setIfNotSet($this->formSpec, F_CLASS_PILL, $class);
// Take default from config.ini
$class = $this->store->getVar(SYSTEM_CSS_CLASS_QFQ_FORM_BODY, STORE_SYSTEM);
$class = $class ? $class : 'qfq-color-grey-2';
Support::setIfNotSet($this->formSpec, F_CLASS_BODY, $class);
$this->formSpec = $formSpec;
// Clear
$this->store->setVar(SYSTEM_FORM_ELEMENT, '', STORE_SYSTEM);
// FE: Action
// $this->feSpecAction = $this->eval->parseArray($this->db->sql(SQL_FORM_ELEMENT_ALL_CONTAINER, ROW_REGULAR,
// ['no', $this->formSpec["id"], 'action']));
$this->feSpecAction = $this->db->sql(SQL_FORM_ELEMENT_ALL_CONTAINER, ROW_REGULAR, ['no', $this->formSpec["id"], 'action']);
HelperFormElement::explodeParameterInArrayElements($this->feSpecAction);
......@@ -438,6 +421,8 @@ class QuickFormQuery {
// Expand F_FE_PARAMETER ('parameter')
HelperFormElement::explodeParameterInArrayElements($this->feSpecNative);
$this->feSpecNative = $this->copyAttributesToFormElements($this->formSpec, $this->feSpecNative);
$this->feSpecNative = HelperFormElement::duplicateRetypeElements($this->feSpecNative);
return $formName;
......@@ -507,7 +492,7 @@ class QuickFormQuery {
* @param array $form
* @return array
*/
private function modeAdjustFormConfig($mode, array $form) {
private function modeCleanFormConfig($mode, array $form) {
switch ($mode) {
case FORM_DELETE:
......@@ -520,6 +505,64 @@ class QuickFormQuery {
return $form;
}
/**
* @param array $formSpec
* @return array
*/
private function setFormDefault(array $formSpec) {
# Set defaults:
Support::setIfNotSet($formSpec, 'class', '');
Support::setIfNotSet($formSpec, F_BS_LABEL_COLUMNS, 3, '');
Support::setIfNotSet($formSpec, F_BS_INPUT_COLUMNS, 6, '');
Support::setIfNotSet($formSpec, F_BS_NOTE_COLUMNS, 3, '');
Support::setIfNotSet($formSpec, F_SUBMIT_BUTTON_TEXT, '');
Support::setIfNotSet($formSpec, F_EXTRA_DELETE_FORM, '');
// Take default from config.ini
$value = $this->store->getVar(SYSTEM_FORM_DATA_PATTERN_ERROR, STORE_SYSTEM);
Support::setIfNotSet($formSpec, F_FE_DATA_PATTERN_ERROR, ($value !== false) ? $value : '');
// Take default from config.ini
$value = $this->store->getVar(SYSTEM_FORM_DATA_REQUIRED_ERROR, STORE_SYSTEM);
Support::setIfNotSet($formSpec, F_FE_DATA_REQUIRED_ERROR, ($value !== false) ? $value : '');
// Take default from config.ini
$value = $this->store->getVar(SYSTEM_FORM_DATA_MATCH_ERROR, STORE_SYSTEM);
Support::setIfNotSet($formSpec, F_FE_DATA_MATCH_ERROR, ($value !== false) ? $value : '');
// Take default from config.ini
$value = $this->store->getVar(SYSTEM_FORM_DATA_ERROR, STORE_SYSTEM);
Support::setIfNotSet($formSpec, F_FE_DATA_ERROR, ($value !== false) ? $value : '');
// Take default from config.ini
$class = $this->store->getVar(SYSTEM_CSS_CLASS_QFQ_FORM_PILL, STORE_SYSTEM);
$class = $class ? $class : 'qfq-color-grey-1';
Support::setIfNotSet($formSpec, F_CLASS_PILL, $class);
// Take default from config.ini
$class = $this->store->getVar(SYSTEM_CSS_CLASS_QFQ_FORM_BODY, STORE_SYSTEM);
$class = $class ? $class : 'qfq-color-grey-2';
Support::setIfNotSet($formSpec, F_CLASS_BODY, $class);
return $formSpec;
}
/**
* @param $feSpecNative
* @return mixed
*/
private function copyAttributesToFormElements(array $formSpec, array $feSpecNative) {
foreach ($feSpecNative as $key => $element) {
Support::setIfNotSet($feSpecNative[$key], F_FE_DATA_PATTERN_ERROR, $formSpec[F_FE_DATA_PATTERN_ERROR]);
Support::setIfNotSet($feSpecNative[$key], F_FE_DATA_REQUIRED_ERROR, $formSpec[F_FE_DATA_REQUIRED_ERROR]);
Support::setIfNotSet($feSpecNative[$key], F_FE_DATA_MATCH_ERROR, $formSpec[F_FE_DATA_MATCH_ERROR]);
Support::setIfNotSet($feSpecNative[$key], F_FE_DATA_ERROR, $formSpec[F_FE_DATA_ERROR]);
}
return $feSpecNative;
}
/**
* Check if loading of the given form is permitted. If not, throw an exception.
*
......
......@@ -98,7 +98,7 @@ class HelperFormElement
foreach ($elements as $fe) {
// adjust FE_RETYPE
// adjust FE_RETYPE=1
if (isset($fe[FE_RETYPE]) && ($fe[FE_RETYPE] == '' || $fe[FE_RETYPE] == '1')) {
$fe[FE_RETYPE] = '1';
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment