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

Merge branch 'F8204PositionRequiredMark' into 'master'

F8204 position required mark

See merge request !166
parents bdc0c44c d58c86ac
Pipeline #2057 passed with stages
in 2 minutes and 28 seconds
......@@ -2516,6 +2516,8 @@ Parameter
+-----------------------------+--------+----------------------------------------------------------------------------------------------------------+
| maxFileSize | int | Overwrite default from configuration_ . |
+-----------------------------+--------+----------------------------------------------------------------------------------------------------------+
| requiredPosition | int | See requiredPosition_ . |
+-----------------------------+--------+----------------------------------------------------------------------------------------------------------+
* Example:
......@@ -3027,6 +3029,8 @@ See also at specific *FormElement* definitions.
| messageFail | string | |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
| dataReference | string | Optional. See `applicationTest`_ |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
| requiredPosition | int | See requiredPosition_ . |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
......@@ -3090,6 +3094,21 @@ extraButtonInfo
* For `FormElement` with mode `below`, a `span` element with the given class in `extraButtonInfoClass` (FE, F, configuration_)
will be applied. E.g. this might be `pull-right` to align the `info` button/icon on the right side below the input element.
.. _`requiredPosition`:
Required Position
^^^^^^^^^^^^^^^^^
By default, input elements with `Mode=required` will be displayed with a 'red asterix' right beside the label. The position
of the 'red asterix' can be choosen via the `parameter` field::
requiredPosition = label-left|label-right|input-left|input-right|note-left|note-right
The default is 'label-right'.
The definition can be set per Form (=affects all FormElements) or per FormElement.
.. _`input-checkbox`:
Type: checkbox
......
......@@ -8,19 +8,19 @@
namespace IMATHUZH\Qfq\Core;
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\Store\Sip;
use IMATHUZH\Qfq\Core\Store\Store;
use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\HelperFormElement;
use IMATHUZH\Qfq\Core\Helper\OnArray;
use IMATHUZH\Qfq\Core\Helper\KeyValueStringParser;
use IMATHUZH\Qfq\Core\Helper\Ldap;
use IMATHUZH\Qfq\Core\Helper\Logger;
use IMATHUZH\Qfq\Core\Helper\KeyValueStringParser;
use IMATHUZH\Qfq\Core\Report\Link;
use IMATHUZH\Qfq\Core\Helper\OnArray;
use IMATHUZH\Qfq\Core\Helper\Sanitize;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\Report\Link;
use IMATHUZH\Qfq\Core\Report\Report;
use IMATHUZH\Qfq\Core\Store\Sip;
use IMATHUZH\Qfq\Core\Store\Store;
/**
* Class AbstractBuildForm
......@@ -958,6 +958,7 @@ abstract class AbstractBuildForm {
* @throws \UserFormException
*/
private function getFormElementForJson($htmlFormElementName, $value, array $formElement) {
$addClassRequired = array();
$json = $this->getJsonFeMode($formElement[FE_MODE]); // disabled, required
......@@ -984,14 +985,20 @@ abstract class AbstractBuildForm {
// }
}
if ($formElement[FE_MODE] == FE_MODE_REQUIRED || $formElement[FE_MODE] == FE_MODE_SHOW_REQUIRED) {
$addClassRequired = HelperFormElement::getRequiredPositionClass($formElement[F_FE_REQUIRED_POSITION]);
}
if (isset($formElement[FE_LABEL])) {
$key = $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_LABEL;
$addClass = ($formElement[FE_MODE] == FE_MODE_REQUIRED || $formElement[FE_MODE] == FE_MODE_SHOW_REQUIRED) ? CSS_REQUIRED : '';
$json[API_ELEMENT_UPDATE][$key][API_ELEMENT_CONTENT] = $this->buildLabel($htmlFormElementName, $formElement[FE_LABEL], $addClass);
$json[API_ELEMENT_UPDATE][$key][API_ELEMENT_CONTENT] = $this->buildLabel($htmlFormElementName, $formElement[FE_LABEL], $addClassRequired[FE_LABEL] ?? '');
}
if (isset($formElement[FE_NOTE])) {
$key = $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_NOTE;
if (!empty($addClassRequired[FE_NOTE])) {
$formElement[FE_NOTE] = Support::wrapTag('<span class="' . $addClassRequired[FE_NOTE] . '">', $formElement[FE_NOTE]);
}
$json[API_ELEMENT_UPDATE][$key][API_ELEMENT_CONTENT] = $formElement[FE_NOTE];
}
......@@ -1041,6 +1048,10 @@ abstract class AbstractBuildForm {
$class .= ' hidden';
}
if (!empty($addClassRequired[FE_INPUT])) {
$class .= ' ' . $addClassRequired[FE_INPUT];
}
$key = $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_ROW;
$json[API_ELEMENT_UPDATE][$key][API_ELEMENT_ATTRIBUTE]['class'] = $class;
}
......
......@@ -8,11 +8,11 @@
namespace IMATHUZH\Qfq\Core;
use IMATHUZH\Qfq\Core\Helper\HelperFormElement;
use IMATHUZH\Qfq\Core\Helper\Logger;
use IMATHUZH\Qfq\Core\Helper\OnArray;
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\Helper\HelperFormElement;
/**
* Class BuildFormBootstrap
......@@ -728,6 +728,7 @@ EOF;
$htmlLabel = '';
$classHideRow = '';
$classHideElement = '';
$addClassRequired = array();
if ($formElement[FE_MODE] == FE_MODE_HIDDEN) {
if ($formElement[FE_FLAG_ROW_OPEN_TAG] && $formElement[FE_FLAG_ROW_CLOSE_TAG]) {
......@@ -737,23 +738,32 @@ EOF;
}
}
if ($formElement[FE_MODE] == FE_MODE_REQUIRED || $formElement[FE_MODE] == FE_MODE_SHOW_REQUIRED) {
$addClassRequired = HelperFormElement::getRequiredPositionClass($formElement[F_FE_REQUIRED_POSITION]);
}
// Label
if ($formElement[FE_BS_LABEL_COLUMNS] != '0') {
$addClass = ($formElement[FE_MODE] == FE_MODE_REQUIRED || $formElement[FE_MODE] == FE_MODE_SHOW_REQUIRED) ? CSS_REQUIRED : '';
$htmlLabel = $this->buildLabel($htmlFormElementName, $formElement[FE_LABEL], $addClass);
$htmlLabel = $this->buildLabel($htmlFormElementName, $formElement[FE_LABEL], $addClassRequired[FE_LABEL] ?? '');
}
$html .= $this->customWrap($formElement, $htmlLabel, FE_WRAP_LABEL, $formElement[FE_BS_LABEL_COLUMNS],
[$this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_START], $this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_END]], $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_LABEL);
// Input
if (!empty($addClassRequired[FE_INPUT])) {
$htmlElement = Support::wrapTag('<span class="' . $addClassRequired[FE_INPUT] . '">', $htmlElement);
}
$html .= $this->customWrap($formElement, $htmlElement, FE_WRAP_INPUT, $formElement[FE_BS_INPUT_COLUMNS],
[$this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_START], $this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_END]],
$formElement[FE_HTML_ID] . HTML_ID_EXTENSION_INPUT, $classHideElement);
if (!empty($addClassRequired[FE_NOTE])) {
$formElement[FE_NOTE] = Support::wrapTag('<span class="' . $addClassRequired[FE_NOTE] . '">', $formElement[FE_NOTE]);
}
// Note
$note = $formElement[FE_NOTE];
$html .= $this->customWrap($formElement, $note, FE_WRAP_NOTE, $formElement[FE_BS_NOTE_COLUMNS],
$html .= $this->customWrap($formElement, $formElement[FE_NOTE], FE_WRAP_NOTE, $formElement[FE_BS_NOTE_COLUMNS],
[$this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_START], $this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_END]], $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_NOTE);
// Row
......
......@@ -674,7 +674,8 @@ const DOWNLOAD_POPUP_REPLACE_TITLE = '#downloadPopupReplaceTitle#';
const SYSTEM_DRAG_AND_DROP_JS = 'hasDragAndDropJS';
const SYSTEM_PARAMETER_LANGUAGE_FIELD_NAME = 'parameterLanguageFieldName';
const CSS_REQUIRED = 'required-field';
const CSS_REQUIRED_RIGHT = 'required-right';
const CSS_REQUIRED_LEFT = 'required-left';
// die folgenden Elemente sind vermutlich nicht noetig, wenn Store Klassen globale Vars benutzt.
//const SYSTEM_FORM_DEF = 'formDefinition'; // Type: SANITIZE_ALNUMX / AssocArray. Final form to process. Useful for error reporting.
......@@ -963,6 +964,13 @@ const F_FE_DATA_MATCH_ERROR_DEFAULT = 'Fields do not match'; // Attention: the d
const F_FE_LABEL_ALIGN = SYSTEM_LABEL_ALIGN;
const F_FE_LABEL_ALIGN_DEFAULT = 'default';
const F_FE_REQUIRED_POSITION = 'requiredPosition';
const F_FE_REQUIRED_POSITION_LABEL_LEFT = 'label-left';
const F_FE_REQUIRED_POSITION_LABEL_RIGHT = 'label-right';
const F_FE_REQUIRED_POSITION_INPUT_LEFT = 'input-left';
const F_FE_REQUIRED_POSITION_INPUT_RIGHT = 'input-right';
const F_FE_REQUIRED_POSITION_NOTE_LEFT = 'note-left';
const F_FE_REQUIRED_POSITION_NOTE_RIGHT = 'note-right';
const F_PARAMETER = 'parameter'; // valid for F_ and FE_
......@@ -1059,6 +1067,7 @@ const FE_VALUE = 'value';
const FE_CLASS = 'class';
const FE_LABEL = 'label';
const FE_NOTE = 'note';
const FE_INPUT = 'input';
const FE_BS_LABEL_COLUMNS = F_BS_LABEL_COLUMNS;
const FE_BS_INPUT_COLUMNS = F_BS_INPUT_COLUMNS;
const FE_BS_NOTE_COLUMNS = F_BS_NOTE_COLUMNS;
......
......@@ -851,7 +851,7 @@ class Database {
$feSpecNative = $this->sql($sql, ROW_REGULAR, $param);
$feSpecNative = HelperFormElement::formElementSetDefault($feSpecNative);
$feSpecNative = HelperFormElement::formElementSetDefault($feSpecNative, $formSpec);
// Explode and Do $FormElement.parameter
HelperFormElement::explodeParameterInArrayElements($feSpecNative, FE_PARAMETER);
......
......@@ -9,7 +9,7 @@
namespace IMATHUZH\Qfq\Core\Helper;
use IMATHUZH\Qfq\Core\Store\Store;
/**
* Class HelperFormElement
......@@ -40,16 +40,20 @@ class HelperFormElement {
/**
* Set default values for given FormElement.
* Hint: to copy values from Form, copyAttributesToFormElements() is more appropriate.
*
* @param array $elements
*
* @param array $formSpec
* @return array
*/
public static function formElementSetDefault(array $elements) {
public static function formElementSetDefault(array $elements, array $formSpec) {
foreach ($elements AS $key => $element) {
$elements[$key][FE_TG_INDEX] = 0;
unset($elements[$key][FE_ADMIN_NOTE]);
// $elements[$key][FE_DATA_REFERENCE] = '';
}
return $elements;
......@@ -89,9 +93,11 @@ class HelperFormElement {
// For retype elements: copy the language specific value.
if (isset($element[FE_RETYPE_SOURCE_NAME])) {
if (!empty($element[FE_RETYPE_LABEL])) {
$element[FE_LABEL] = $element[FE_RETYPE_LABEL];
}
if (!empty($element[FE_RETYPE_NOTE])) {
$element[FE_NOTE] = $element[FE_RETYPE_NOTE];
}
......@@ -271,6 +277,7 @@ class HelperFormElement {
if ($feSpecNative[$key][F_FE_LABEL_ALIGN] == F_FE_LABEL_ALIGN_DEFAULT) {
$feSpecNative[$key][F_FE_LABEL_ALIGN] = $formSpec[F_FE_LABEL_ALIGN];
}
Support::setIfNotSet($feSpecNative[$key], F_FE_REQUIRED_POSITION, $formSpec[F_FE_REQUIRED_POSITION]);
}
return $feSpecNative;
......@@ -464,4 +471,41 @@ EOF;
return json_encode($rgb);
}
/**
* Depending on value in $requiredPosition the array $classArr will contain the CSS class to align the required mark.
* @param $requiredPosition
* @return array
* @throws \UserFormException
*/
public static function getRequiredPositionClass($requiredPosition) {
$classArr[FE_LABEL] = '';
$classArr[FE_TYPE] = '';
$classArr[FE_NOTE] = '';
switch ($requiredPosition) {
case F_FE_REQUIRED_POSITION_LABEL_LEFT:
$classArr[FE_LABEL] = CSS_REQUIRED_LEFT;
break;
case F_FE_REQUIRED_POSITION_LABEL_RIGHT:
$classArr[FE_LABEL] = CSS_REQUIRED_RIGHT;
break;
case F_FE_REQUIRED_POSITION_INPUT_LEFT:
$classArr[FE_INPUT] = CSS_REQUIRED_LEFT;
break;
case F_FE_REQUIRED_POSITION_INPUT_RIGHT:
$classArr[FE_INPUT] = CSS_REQUIRED_RIGHT;
break;
case F_FE_REQUIRED_POSITION_NOTE_LEFT:
$classArr[FE_NOTE] = CSS_REQUIRED_LEFT;
break;
case F_FE_REQUIRED_POSITION_NOTE_RIGHT:
$classArr[FE_NOTE] = CSS_REQUIRED_RIGHT;
break;
default:
throw new \UserFormException('Unkown value for ' . F_FE_REQUIRED_POSITION . ': ' . $requiredPosition, ERROR_INVALID_VALUE);
}
return $classArr;
}
}
\ No newline at end of file
......@@ -1144,7 +1144,7 @@ class QuickFormQuery {
$feSpecNative = $this->dbArray[$this->dbIndexQfq]->sql($sql, ROW_REGULAR, $param);
$feSpecNative = HelperFormElement::formElementSetDefault($feSpecNative);
$feSpecNative = HelperFormElement::formElementSetDefault($feSpecNative, $formSpec);
// Explode and Do $FormElement.parameter
HelperFormElement::explodeParameterInArrayElements($feSpecNative, FE_PARAMETER);
......@@ -1403,6 +1403,7 @@ class QuickFormQuery {
Support::setIfNotSet($formSpec, F_DB_INDEX, $this->store->getVar(F_DB_INDEX, STORE_SYSTEM));
Support::setIfNotSet($formSpec, F_ENTER_AS_SUBMIT, $this->store->getVar(SYSTEM_ENTER_AS_SUBMIT, STORE_SYSTEM));
Support::setIfNotSet($formSpec, F_SESSION_TIMEOUT_SECONDS, $this->store->getVar(SYSTEM_SESSION_TIMEOUT_SECONDS, STORE_SYSTEM));
Support::setIfNotSet($formSpec, F_FE_REQUIRED_POSITION, F_FE_REQUIRED_POSITION_LABEL_RIGHT);
// In case there is no F_MODE defined on the form, check if there is one in STORE_SIP.
if ($formSpec[F_MODE] == '') {
......
......@@ -98,7 +98,7 @@ select.qfq-locked:invalid {
// margin-left: -10px;
//}
.required-field:after {
.required-right:after {
color: #d00;
content: "*";
//position: absolute;
......@@ -106,6 +106,14 @@ select.qfq-locked:invalid {
//top: 10px;
}
.required-left:before {
color: #d00;
content: "*";
//position: absolute;
margin-right: 3px;
//top: 10px;
}
.qfq-table-50 {
min-width: 50%;
width: auto;
......
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