Commit 8c9dc75a authored by Morton Jonuschat's avatar Morton Jonuschat Committed by Christian Kuhn
Browse files

[TASK] FormEngine: Remove name="foo[bar]_hr" from input fields

Update the handling of human readable fields so that the values are not
being set and only the hidden field with the actual value is submitted.

This patch also updates the handling for the _list and _mul appendixes
as these use the same methods and needed to be changed as well.

Resolves: #69672
Releases: master
Change-Id: I7a92c924a567621c2f79c736f878af288595c657
Reviewed-on: http://review.typo3.org/43254

Reviewed-by: Nicole Cordes's avatarNicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes's avatarNicole Cordes <typo3@cordes.co>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 878dcb78
......@@ -565,7 +565,7 @@ abstract class AbstractFormElement extends AbstractNode {
$selector = '<select id="' . StringUtility::getUniqueId('tceforms-multiselect-') . '" '
. ($params['noList'] ? 'style="display: none"' : 'size="' . $sSize . '" class="form-control tceforms-multiselect"')
. ($isMultiple ? ' multiple="multiple"' : '')
. ' name="' . $fName . '_list" ' . $this->getValidationDataAsDataAttribute($config) . $onFocus . $params['style'] . $disabled . '>' . implode('', $opt)
. ' data-formengine-input-name="' . htmlspecialchars($fName) . '" ' . $this->getValidationDataAsDataAttribute($config) . $onFocus . $params['style'] . $disabled . '>' . implode('', $opt)
. '</select>';
}
$icons = array(
......
......@@ -126,14 +126,13 @@ class CheckboxElement extends AbstractFormElement {
$numberOfItems,
implode('', $additionalInformation['fieldChangeFunc'])
);
$checkboxName = $additionalInformation['itemFormElName'] . '_' . $itemCounter;
$checkboxId = $additionalInformation['itemFormElID'] . '_' . $itemCounter;
return '
<div class="checkbox' . ($inline ? ' checkbox-inline' : '') . (!$disabled ? '' : ' disabled') . '">
<label>
<input type="checkbox"
value="1"
name="' . htmlspecialchars($checkboxName) . '"
data-formengine-input-name="' . htmlspecialchars($additionalInformation['itemFormElName']) . '"
' . $checkboxParameters . '
' . $additionalInformation['onFocus'] . '
' . (!$disabled ?: ' disabled="disabled"') . '
......
......@@ -88,7 +88,7 @@ class GroupElement extends AbstractFormElement {
. ', \'RemoveFirstIfFull\', ' . GeneralUtility::quoteJSvalue($maxitems) . '); ' . $parameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
}
$html = '<input type="hidden" class="t3js-group-hidden-field" name="' . $parameterArray['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '"' . $disabled . ' />';
$html = '<input type="hidden" class="t3js-group-hidden-field" data-formengine-input-name="' . htmlspecialchars($parameterArray['itemFormElName']) . '" value="' . ($config['multiple'] ? 1 : 0) . '"' . $disabled . ' />';
// Define parameters for all types below
$commonParameters = array(
......
......@@ -169,8 +169,8 @@ class InputTextElement extends AbstractFormElement {
// calculate attributes
$attributes['data-formengine-validation-rules'] = $this->getValidationDataAsJsonString($config);
$attributes['data-formengine-input-params'] = json_encode($paramsList);
$attributes['data-formengine-input-name'] = htmlspecialchars($parameterArray['itemFormElName']);
$attributes['id'] = StringUtility::getUniqueId('formengine-input-');
$attributes['name'] = $parameterArray['itemFormElName'] . '_hr';
$attributes['value'] = '';
if (isset($config['max']) && (int)$config['max'] > 0) {
$attributes['maxlength'] = (int)$config['max'];
......@@ -236,7 +236,8 @@ class InputTextElement extends AbstractFormElement {
$row,
$fieldName,
$parameterArray,
$parameterArray['itemFormElName'] . '_hr', $specConf
$parameterArray['itemFormElName'],
$specConf
);
// Add a wrapper to remain maximum width
......
......@@ -88,7 +88,7 @@ class SelectMultipleSideBySideElement extends AbstractFormElement {
}
// Setting this hidden field (as a flag that JavaScript can read out)
if (!$disabled) {
$item .= '<input type="hidden" name="' . $parameterArray['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '" />';
$item .= '<input type="hidden" data-formengine-input-name="' . htmlspecialchars($parameterArray['itemFormElName']) . '" value="' . ($config['multiple'] ? 1 : 0) . '" />';
}
// Set max and min items:
$maxitems = MathUtility::forceIntegerInRange($config['maxitems'], 0);
......@@ -159,7 +159,7 @@ class SelectMultipleSideBySideElement extends AbstractFormElement {
$multiSelectId = StringUtility::getUniqueId('tceforms-multiselect-');
$itemsToSelect = '
<select data-relatedfieldname="' . htmlspecialchars($parameterArray['itemFormElName']) . '" data-exclusivevalues="'
. htmlspecialchars($config['exclusiveKeys']) . '" id="' . $multiSelectId . '" name="' . htmlspecialchars($parameterArray['itemFormElName']) . '_sel" '
. htmlspecialchars($config['exclusiveKeys']) . '" id="' . $multiSelectId . '" data-formengine-input-name="' . htmlspecialchars($parameterArray['itemFormElName']) . '" '
. ' class="form-control t3js-formengine-select-itemstoselect" '
. ($size ? ' size="' . $size . '"' : '') . ' onchange="' . htmlspecialchars($sOnChange) . '"'
. $parameterArray['onFocus'] . $this->getValidationDataAsDataAttribute($config) . $selector_itemListStyle . '>
......
......@@ -423,8 +423,17 @@ define('TYPO3/CMS/Backend/FormEngine', ['jquery'], function ($) {
// if an appendix is set, return the field with the appendix (like _mul or _list)
if (appendix) {
var $fieldEl = $(':input[name="' + fieldName + appendix + '"]', $formEl);
if ($fieldEl.length > 0 || noFallback === true) {
var $fieldEl;
switch (appendix) {
case '_list':
$fieldEl = $(':input.tceforms-multiselect[data-formengine-input-name="' + fieldName + '"]', $formEl);
break;
case '_mul':
case '_hr':
$fieldEl = $(':input[type=hidden][data-formengine-input-name="' + fieldName + '"]', $formEl);
break;
}
if (($fieldEl && $fieldEl.length > 0) || noFallback === true) {
return $fieldEl;
}
}
......
......@@ -109,7 +109,7 @@ define('TYPO3/CMS/Backend/FormEngineValidation', ['jquery', 'TYPO3/CMS/Backend/F
*/
FormEngineValidation.initializeInputField = function(fieldName) {
var $field = $('[name="' + fieldName + '"]');
var $humanReadableField = $('[name="' + fieldName + '_hr"]');
var $humanReadableField = $('[data-formengine-input-name="' + fieldName + '"]');
var $checkboxField = $('[name="' + fieldName + '_cb"]');
var $mainField = $('[name="' + $field.data('main-field') + '"]');
if ($mainField.length === 0) {
......@@ -143,14 +143,14 @@ define('TYPO3/CMS/Backend/FormEngineValidation', ['jquery', 'TYPO3/CMS/Backend/F
$humanReadableField.data('main-field', fieldName);
$humanReadableField.data('config', config);
$humanReadableField.on('change', function() {
FormEngineValidation.updateInputField($(this).attr('name'));
FormEngineValidation.updateInputField($(this).attr('data-formengine-input-name'));
});
$humanReadableField.on('keyup', FormEngineValidation.validate);
$checkboxField.data('main-field', fieldName);
$checkboxField.data('config', config);
$checkboxField.on('click', function() {
FormEngineValidation.updateInputField($(this).attr('name'));
FormEngineValidation.updateInputField($(this).attr('data-formengine-input-name'));
});
};
......@@ -216,7 +216,7 @@ define('TYPO3/CMS/Backend/FormEngineValidation', ['jquery', 'TYPO3/CMS/Backend/F
if ($mainField.length === 0) {
$mainField = $field;
}
var $humanReadableField = $('[name="' + $mainField.attr('name') + '_hr"]');
var $humanReadableField = $('[data-formengine-input-name="' + $mainField.attr('name') + '"]');
var config = $mainField.data('config');
if (typeof config !== 'undefined') {
......
......@@ -145,7 +145,7 @@ var TBE_EDITOR = {
// modify the "field has changed" info by adding a class to the container element (based on palette or main field)
var $formField = TYPO3.jQuery('[name="' + el + '"]');
var $humanReadableField = TYPO3.jQuery('[name="' + el + '_hr"]');
var $humanReadableField = TYPO3.jQuery('[data-formengine-input-name="' + el + '"]');
$humanReadableField.triggerHandler('change');
var $paletteField = $formField.closest('.t3js-formengine-palette-field');
$paletteField.addClass('has-change');
......@@ -387,16 +387,14 @@ var typo3form = {
$formFieldItemWrapper.find('.t3js-formengine-placeholder-formfield').toggle(!showPlaceholder);
},
fieldSet: function(theField, evallist, is_in, checkbox, checkboxValue) {
var i;
if (document[TBE_EDITOR.formname][theField]) {
var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
var theValue = document[TBE_EDITOR.formname][theField].value;
if (checkbox && theValue==checkboxValue) {
document[TBE_EDITOR.formname][theField+"_hr"].value="";
document.querySelector('form[name="' + TBE_EDITOR.formname + '"] [data-formengine-input-name="' + theField + '"]').value = "";
if (document[TBE_EDITOR.formname][theField+"_cb"]) document[TBE_EDITOR.formname][theField+"_cb"].checked = "";
} else {
document[TBE_EDITOR.formname][theField+"_hr"].value = evalFunc.outputObjValue(theFObj, theValue);
document.querySelector('form[name="' + TBE_EDITOR.formname + '"] [data-formengine-input-name="' + theField + '"]').value = evalFunc.outputObjValue(theFObj, theValue);
if (document[TBE_EDITOR.formname][theField+"_cb"]) document[TBE_EDITOR.formname][theField+"_cb"].checked = "on";
}
}
......@@ -423,7 +421,7 @@ var typo3form = {
document[TBE_EDITOR.formname][theField].value=checkboxValue;
}
}else{
document[TBE_EDITOR.formname][theField].value = evalFunc.evalObjValue(theFObj, document[TBE_EDITOR.formname][theField+"_hr"].value);
document[TBE_EDITOR.formname][theField].value = evalFunc.evalObjValue(theFObj, document.querySelector('form[name="' + TBE_EDITOR.formname + '"] [data-formengine-input-name="' + theField + '"]').value);
}
typo3form.fieldSet(theField, evallist, is_in, checkbox, checkboxValue);
}
......
......@@ -1608,7 +1608,7 @@ class QueryGenerator {
$id = StringUtility::getUniqueId('dt_');
$html = array();
$html[] = '<div class="input-group" id="' . $id . '-wrapper">';
$html[] = ' <input name="' . htmlspecialchars($name) . '_hr" value="' . $value . '" class="form-control t3js-datetimepicker t3js-clearable" data-date-type="' . htmlspecialchars($type) . '" data-date-offset="0" type="text" id="' . $id . '">';
$html[] = ' <input data-formengine-input-name="' . htmlspecialchars($name) . '" value="' . $value . '" class="form-control t3js-datetimepicker t3js-clearable" data-date-type="' . htmlspecialchars($type) . '" data-date-offset="0" type="text" id="' . $id . '">';
$html[] = ' <input name="' . htmlspecialchars($name) . '" value="' . (int)$timestamp . '" type="hidden">';
$html[] = ' <span class="input-group-btn">';
$html[] = ' <label class="btn btn-default" for="' . $id . '">';
......
......@@ -620,9 +620,9 @@ class ElementBrowser {
return false;
}
function checkReference() { //
if (window.opener && window.opener.document && window.opener.document.' . $this->P['formName']
. ' && window.opener.document.' . $this->P['formName'] . '["' . $this->P['itemName'] . '"] ) {
return window.opener.document.' . $this->P['formName'] . '["' . $this->P['itemName'] . '"];
if (window.opener && window.opener.document && window.opener.document.querySelector(\'form[name="'
. $this->P['formName'] . '"] [data-formengine-input-name="' . $this->P['itemName'] . '"]\')) {
return window.opener.document.querySelector(\'form[name="' . $this->P['formName'] . '"] [data-formengine-input-name="' . $this->P['itemName'] . '"]\');
} else {
close();
}
......
......@@ -108,8 +108,8 @@ class RsaInputElement extends AbstractFormElement {
// calculate attributes
$attributes['data-formengine-validation-rules'] = $this->getValidationDataAsJsonString($config);
$attributes['data-formengine-input-params'] = json_encode($paramsList);
$attributes['data-formengine-input-name'] = htmlspecialchars($parameterArray['itemFormElName']);
$attributes['id'] = StringUtility::getUniqueId('formengine-input-');
$attributes['name'] = $parameterArray['itemFormElName'] . '_hr';
if (isset($config['max']) && (int)$config['max'] > 0) {
$attributes['maxlength'] = (int)$config['max'];
}
......@@ -161,7 +161,8 @@ class RsaInputElement extends AbstractFormElement {
$row,
$fieldName,
$parameterArray,
$parameterArray['itemFormElName'] . '_hr', $specConf
$parameterArray['itemFormElName'],
$specConf
);
// Add a wrapper to remain maximum width
......
Supports Markdown
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