Commit e0b1788b authored by Carsten  Rose's avatar Carsten Rose
Browse files

unify attributes for checkboxSingle

parent 58f8fd0f
Pipeline #2882 passed with stages
in 3 minutes and 58 seconds
......@@ -17,7 +17,6 @@ namespace IMATHUZH\Qfq\Core\Form;
//use IMATHUZH\Qfq\Core\Helper\OnArray;
//use IMATHUZH\Qfq\Core\Helper\Sanitize;
use IMATHUZH\Qfq\Core\Helper\Support;
//use IMATHUZH\Qfq\Core\Report\Link;
//use IMATHUZH\Qfq\Core\Report\Report;
//use IMATHUZH\Qfq\Core\Store\Sip;
......@@ -395,19 +394,30 @@ class Checkbox {
*/
public function buildCheckboxSingle(array $formElement, $htmlFormElementName, $attribute, $value, array &$json, $mode = FORM_LOAD) {
if (isset($formElement[FE_BUTTON_CLASS])) {
// Bootstrap
$attribute .= Support::doAttribute('id', $formElement[FE_HTML_ID]);
$attribute .= Support::doAttribute('name', $htmlFormElementName);
$attribute .= Support::doAttribute('value', $formElement[FE_CHECKBOX_CHECKED], false);
$attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute(ATTRIBUTE_DATA_REFERENCE, $formElement[FE_DATA_REFERENCE]);
if ($formElement[FE_BUTTON_CLASS] == '') {
$formElement[FE_BUTTON_CLASS] = 'btn-default';
}
$classActive = '';
$valueJson = false;
if ($formElement[FE_MODE] == FE_MODE_READONLY) {
$formElement[FE_BUTTON_CLASS] .= ' disabled';
}
if ($formElement[FE_CHECKBOX_CHECKED] === $value) {
$attribute .= Support::doAttribute('checked', 'checked');
$valueJson = $value;
}
//$attribute .= HelperFormElement::getAttributeList($formElement, [FE_AUTOFOCUS, F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$attribute .= HelperFormElement::getAttributeList($formElement, [FE_AUTOFOCUS, F_FE_DATA_REQUIRED_ERROR]);
return $this->constructCheckboxSingleButton($formElement, $htmlFormElementName, $attribute, $value, $json);
if (isset($formElement[FE_BUTTON_CLASS])) {
// Bootstrap
return $this->constructCheckboxSingleBootstrap($formElement, $htmlFormElementName, $attribute, $value, $json, $valueJson);
} else {
return $this->constructCheckboxSinglePlain($formElement, $htmlFormElementName, $attribute, $value, $json);
// Plain
return $this->constructCheckboxSinglePlain($formElement, $htmlFormElementName, $attribute, $value, $json, $valueJson);
}
}
......@@ -432,27 +442,22 @@ class Checkbox {
* @throws \CodeException
* @throws \UserFormException
*/
public function constructCheckboxSingleButton(array $formElement, $htmlFormElementName, $attribute, $value, array &$json) {
public function constructCheckboxSingleBootstrap(array $formElement, $htmlFormElementName, $attribute, $value, array &$json, $valueJson) {
$html = '';
$valueJson = false;
$attribute .= Support::doAttribute('id', $formElement[FE_HTML_ID]);
$attribute .= Support::doAttribute('name', $htmlFormElementName);
$attribute .= Support::doAttribute('value', $formElement[FE_CHECKBOX_CHECKED], false);
$attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute(FE_INPUT_AUTOCOMPLETE, 'off');
$attribute .= Support::doAttribute(ATTRIBUTE_DATA_REFERENCE, $formElement[FE_DATA_REFERENCE]);
if ($formElement[FE_BUTTON_CLASS] == '') {
$formElement[FE_BUTTON_CLASS] = 'btn-default';
}
if ($formElement[FE_MODE] == FE_MODE_READONLY) {
$formElement[FE_BUTTON_CLASS] .= ' disabled';
}
$classActive = '';
if ($formElement[FE_CHECKBOX_CHECKED] === $value) {
$attribute .= Support::doAttribute('checked', 'checked');
$valueJson = true;
$classActive = ' active';
}
$attribute .= HelperFormElement::getAttributeList($formElement, ['autofocus']);
$attribute .= HelperFormElement::getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$htmlHidden = HelperFormElement::buildNativeHidden($htmlFormElementName, $formElement[FE_CHECKBOX_UNCHECKED]);
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$html = '';
......@@ -619,8 +624,7 @@ class Checkbox {
* Create a 'hidden' input field and a 'checkbox' input field - both with the same HTML 'name'.
* HTML does not submit an unchecked checkbox. Then only the 'hidden' input field is submitted.
*
* Format: <input type="hidden" name="$htmlFormElementName" value="$valueUnChecked">
* <input name="$htmlFormElementName" type="radio" [autofocus="autofocus"]
* <input name="$htmlFormElementName" type="radio" [autofocus="autofocus"]
* [required="required"] [disabled="disabled"] value="<value>" [checked="checked"] >
*
* @param array $formElement
......@@ -633,23 +637,8 @@ class Checkbox {
* @throws \CodeException
* @throws \UserFormException
*/
public function constructCheckboxSinglePlain(array $formElement, $htmlFormElementName, $attribute, $value, array &$json) {
public function constructCheckboxSinglePlain(array $formElement, $htmlFormElementName, $attribute, $value, array &$json, $valueJson) {
$html = '';
$valueJson = false;
$attribute .= Support::doAttribute('id', $formElement[FE_HTML_ID]);
$attribute .= Support::doAttribute('name', $htmlFormElementName);
$attribute .= Support::doAttribute('value', $formElement[FE_CHECKBOX_CHECKED], false);
$attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute(ATTRIBUTE_DATA_REFERENCE, $formElement[FE_DATA_REFERENCE]);
if ($formElement[FE_CHECKBOX_CHECKED] === $value) {
$attribute .= Support::doAttribute('checked', 'checked');
$valueJson = $value;
}
$attribute .= HelperFormElement::getAttributeList($formElement, ['autofocus']);
$attribute .= HelperFormElement::getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$htmlHidden = HelperFormElement::buildNativeHidden($htmlFormElementName, $formElement[FE_CHECKBOX_UNCHECKED]);
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
......
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