Commit 19bb2c34 authored by Carsten  Rose's avatar Carsten Rose

Merge branch 'B8091CheckBoxRequired' into 'master'

B8091 check box required

See merge request !209
parents 08437f5e 2b2e8402
Pipeline #2814 passed with stages
in 2 minutes and 55 seconds
......@@ -83,28 +83,6 @@ module.exports = function (grunt) {
}
]
},
bootstrap_validator: {
files: [
{
cwd: 'node_modules/bootstrap-validator/dist/',
src: [
'validator.min.js'
],
dest: 'js/',
expand: true,
flatten: true
},
{
cwd: 'node_modules/bootstrap-validator/dist/',
src: [
'validator.min.js'
],
dest: typo3_js,
expand: true,
flatten: true
}
]
},
jquery: {
files: [
{
......@@ -485,6 +463,10 @@ module.exports = function (grunt) {
qfqFabric: {
src: ['javascript/src/Plugins/qfq.fabric.js'],
dest: typo3_js + 'qfq.fabric.min.js'
},
qfqValidator: {
src: ['javascript/src/Plugins/validator.js'],
dest: typo3_js + 'validator.min.js'
}
},
jshint: {
......
......@@ -2059,7 +2059,6 @@ abstract class AbstractBuildForm {
if ($formElement[FE_CHECKBOX_CHECKED] === $value) {
$attribute .= Support::doAttribute('checked', 'checked');
// $valueJson = true;
$valueJson = $value;
}
......@@ -2072,7 +2071,7 @@ abstract class AbstractBuildForm {
$html .= '<input ' . $attribute . '>';
if (isset($formElement['label2'])) {
$html .= $formElement['label2'];
$html .= Support::wrapTag("<span style='font-weight: 400;'>", $formElement['label2']);
}
$labelAttribute = Support::doAttribute('title', $formElement[FE_TOOLTIP]);
......@@ -2169,7 +2168,7 @@ abstract class AbstractBuildForm {
$attributeBase .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h');
$key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h', true);
$htmlHidden = $this->buildNativeHidden($key, '');
$this->fillStoreAdditionalFormElementsCheckboxHidden($formElement, $htmlFormElementName, $htmlHidden);
......@@ -2183,13 +2182,13 @@ abstract class AbstractBuildForm {
for ($ii = 0, $jj = 1; $ii < count($itemKey); $ii++, $jj++) {
$jsonValue = false;
$classActive = '';
$htmlFormElementNameUniq = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, $ii);
$htmlFormElementNameUniq = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, $ii, true);
$attribute .= Support::doAttribute('id', $formElement[FE_HTML_ID] . '-' . $ii);
$attribute .= Support::doAttribute('name', $htmlFormElementNameUniq);
$attribute .= Support::doAttribute(ATTRIBUTE_DATA_REFERENCE, $formElement[FE_DATA_REFERENCE] . '-' . $ii);
$attribute .= Support::doAttribute('value', $itemKey[$ii]);
$attribute .= Support::doAttribute('value', $itemKey[$ii], false);
// Check if the given key is found in field.
if (false !== array_search($itemKey[$ii], $values)) {
......@@ -2244,12 +2243,12 @@ abstract class AbstractBuildForm {
$attributeBase .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$attributeBaseLabel = Support::doAttribute('style', 'min-width: ' . $formElement[F_FE_MIN_WIDTH] . 'px;');
// 'font-weight: 400;': class 'checkbox' forces bold for the label - this is not ok.
$attributeBaseLabel = Support::doAttribute('style', 'min-width: ' . $formElement[F_FE_MIN_WIDTH] . 'px; font-weight: 400;');
$key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h');
$htmlHidden = $this->buildNativeHidden($key, '');
$this->fillStoreAdditionalFormElementsCheckboxHidden($formElement, $htmlFormElementName, $htmlHidden);
// $key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h');
// $htmlHidden = $this->buildNativeHidden($key, '');
// $this->fillStoreAdditionalFormElementsCheckboxHidden($formElement, $htmlFormElementName, $htmlHidden);
$html = '';
......@@ -2265,7 +2264,7 @@ abstract class AbstractBuildForm {
for ($ii = 0, $jj = 1; $ii < count($itemKey); $ii++, $jj++) {
$jsonValue = false;
$attribute = $attributeBase;
$htmlFormElementNameUniq = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, $ii);
$htmlFormElementNameUniq = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, $ii, true);
$attribute .= Support::doAttribute('id', $formElement[FE_HTML_ID] . '-' . $ii);
$attribute .= Support::doAttribute('name', $htmlFormElementNameUniq);
$attribute .= Support::doAttribute(ATTRIBUTE_DATA_REFERENCE, $formElement[FE_DATA_REFERENCE] . '-' . $ii);
......@@ -2277,7 +2276,7 @@ abstract class AbstractBuildForm {
$attribute .= Support::doAttribute('autofocus', $formElement[FE_AUTOFOCUS]);
}
$attribute .= Support::doAttribute('value', $itemKey[$ii]);
$attribute .= Support::doAttribute('value', $itemKey[$ii], false);
// Check if the given key is found in field.
if (false !== array_search($itemKey[$ii], $values)) {
......@@ -2291,9 +2290,9 @@ abstract class AbstractBuildForm {
$htmlElement = '<input ' . $attribute . '>' . $value;
// With ALIGN_HORIZONTAL: the label causes some trouble: skip it
if (($orientation === ALIGN_VERTICAL)) {
$htmlElement = Support::wrapTag('<label>', $htmlElement);
}
// if (($orientation === ALIGN_VERTICAL)) {
// $htmlElement = Support::wrapTag('<label>', $htmlElement);
// }
$htmlElement = Support::wrapTag("<label class='$checkboxClass' $attributeBaseLabel>", $htmlElement, true);
......@@ -2497,7 +2496,6 @@ abstract class AbstractBuildForm {
return $this->constructRadioButton($formElement, $htmlFormElementName, $value, $json, $mode);
}
$itemKey = array();
$itemValue = array();
......@@ -2510,7 +2508,7 @@ abstract class AbstractBuildForm {
$attributeBase .= Support::doAttribute('type', $formElement[FE_TYPE]);
$attributeBase .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attributeBaseLabel = Support::doAttribute('style', 'min-width: ' . $formElement[F_FE_MIN_WIDTH] . 'px;');
$attributeBaseLabel = Support::doAttribute('style', 'min-width: ' . $formElement[F_FE_MIN_WIDTH] . 'px; font-weight: 400;');
$jj = 0;
......@@ -2519,7 +2517,7 @@ abstract class AbstractBuildForm {
if ($formElement[FE_MODE] == FE_MODE_READONLY) {
$radioClass .= ' qfq-disabled';
}
$radioOuterTag = ($orientation === ALIGN_HORIZONTAL) ? "label $attributeBaseLabel" : 'div';
// $radioOuterTag = ($orientation === ALIGN_HORIZONTAL) ? "label $attributeBaseLabel" : 'label';
$br = '';
$attribute = $attributeBase;
......@@ -2544,9 +2542,9 @@ abstract class AbstractBuildForm {
$htmlElement = '<input ' . $attribute . '>' . $tmpValue;
// With ALIGN_HORIZONTAL: the label causes some trouble: skip it
if (($orientation === ALIGN_VERTICAL)) {
$htmlElement = Support::wrapTag("<label>", $htmlElement);
}
// if (($orientation === ALIGN_VERTICAL)) {
// $htmlElement = Support::wrapTag("<label>", $htmlElement);
// }
if ($formElement[FE_MAX_LENGTH] > 1) {
......@@ -2560,7 +2558,7 @@ abstract class AbstractBuildForm {
$wrapAttribute = Support::doAttribute('title', $formElement[FE_TOOLTIP]);
$wrapAttribute .= Support::doAttribute('class', $radioClass);
$htmlElement = Support::wrapTag("<$radioOuterTag $wrapAttribute>", $htmlElement) . $br;
$htmlElement = Support::wrapTag("<label $wrapAttribute $attributeBaseLabel>", $htmlElement) . $br;
$html .= $htmlElement;
......
......@@ -207,10 +207,16 @@ class HelperFormElement {
* @param string $field
* @param string $index
*
* @param bool $appendArray
* @return string
*/
public static function prependFormElementNameCheckBoxMulti($field, $index) {
return '_' . $index . '_' . $field;
public static function prependFormElementNameCheckBoxMulti($field, $index, $appendArray = false) {
// return '_' . $index . '_' . $field;
if ($appendArray) {
return $field . '[]';
}
return $field;
}
/**
......
......@@ -12,7 +12,6 @@ use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Evaluate;
use IMATHUZH\Qfq\Core\Helper\HelperFormElement;
use IMATHUZH\Qfq\Core\Helper\Logger;
use IMATHUZH\Qfq\Core\Helper\Sanitize;
use IMATHUZH\Qfq\Core\Helper\Support;
......@@ -258,7 +257,7 @@ class FillStoreForm {
switch ($formElement[FE_TYPE]) {
case FE_TYPE_CHECKBOX:
// Checkbox Multi: collect values
$val = $this->collectMultiValues($clientFieldName, $clientValues);
$val = $this->collectCheckBoxValues($clientFieldName, $clientValues, $formElement[FE_CHECKBOX_CHECKED] ?? '');
if ($val !== false) {
$clientValues[$clientFieldName] = $val;
}
......@@ -280,7 +279,7 @@ class FillStoreForm {
// FORM_REST: typically form elements are filled and created on form load. This does not exist for REST Forms.
// If a FE.value is defined, this has precedence over client supplied content.
if ($formMode == FORM_REST && $formElement[FE_VALUE]!='') {
if ($formMode == FORM_REST && $formElement[FE_VALUE] != '') {
$clientValues[$clientFieldName] = $this->evaluate->parse($formElement[FE_VALUE]);
}
......@@ -353,9 +352,23 @@ class FillStoreForm {
*
* @return string
*/
private function collectMultiValues($clientFieldName, array $clientValues) {
private function collectCheckBoxValues($clientFieldName, array $clientValues, $unchecked) {
// Check for Single
// $checkboxKey = HelperFormElement::prependFormElementNameCheckBoxMulti($clientFieldName, '', false);
if (isset($clientValues[$clientFieldName])) {
if (is_array($clientValues[$clientFieldName])) {
return implode(',', $clientValues[$clientFieldName]);
}
return $clientValues[$clientFieldName];
}
return $unchecked;
$checkboxKey = HelperFormElement::prependFormElementNameCheckBoxMulti($clientFieldName, 'h');
// For templateGroups: all expanded FormElements will be tried to collect - this fails for not submitted fields.
// Therefore skip not existing clientvalues.
......
This diff is collapsed.
......@@ -1119,6 +1119,11 @@ var QfqNS = QfqNS || {};
break;
}
if(this.skipRequiredCheck) {
this.form.$form.validator('update');
this.form.$form.validator('validate');
}
};
n.QfqForm.prototype.getNewButtonTarget = function () {
......
......@@ -248,7 +248,7 @@ i.@{spinner_class} {
position:absolute;
}
.with-errors.help-block {
.qfq-only-active-error .with-errors.help-block {
display: none;
/* visibility: hidden;
margin-bottom: 0;
......@@ -271,7 +271,7 @@ i.@{spinner_class} {
color: #fff;
}
input:focus ~ .with-errors.help-block:not(.hidden), textarea:focus ~ .with-errors.help-block:not(.hidden) {
.input-group ~ .with-errors.help-block:not(.hidden), input:focus ~ .with-errors.help-block:not(.hidden), textarea:focus ~ .with-errors.help-block:not(.hidden) {
display: inline-block;
/* visibility: visible;
max-height: 150px;
......
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