Bug #71514
closed
EXT:form - bring back "Show message in label"
Added by Björn Jacob about 9 years ago.
Updated about 7 years ago.
Description
The wizard allows the following setting "Show message in label". If set the validation message is rendered inside the label. This message is defined via message =
inside a validation rule. This will hide the hint for the user. It is not about hidding the message which is defined via error =
.
Right now this setting does nothing. We have to bring back the functionality.
Files
Hi *,
I tried to fix this issue with an extra property at the element model (showErrors).
In the FormBuilder I write a new method:
/**
* Set the visibility of the mandatory message
* and the validation error message
*
* @param Element $element
* @return void
*/
protected function setVisibilityValidationMessages(Element $element)
{
$elementName = $element->getName();
$userConfiguredFormTyposcript = $this->configuration->getTypoScript();
$rulesTyposcript = isset($userConfiguredFormTyposcript['rules.']) ? $userConfiguredFormTyposcript['rules.'] : null;
if (is_array($rulesTyposcript)) {
$keys = TemplateService::sortedKeyList($rulesTyposcript);
foreach ($keys as $key) {
if (
(int)$key
&& strpos($key, '.') === false
) {
$ruleArguments = $rulesTyposcript[$key . '.'];
$fieldName = $this->formUtility->sanitizeNameAttribute($ruleArguments['element']);
if ($fieldName == $elementName && $ruleArguments['showMessage'] == "1") {
$element->setShowError(true);
break;
}
}
}
}
}
Call this method in 'reviveElement' line 361.
In the fluid view or in the compatibility layer we can ask than for this property and render the errors in the label or not.
The Problem is: We can have many validation messages beneath one element. So I think a clean approach is to add an submodel to 'elements'. That model holds the messages and the visibility.
An other approach is to add messages only if showMessages in TS is set to true, but I think this is a bit 'hacky'.
Any other ideas?
Thx
- Status changed from New to Under Review
Example form for testing:
enctype = multipart/form-data
method = post
prefix = tx_form
confirmation = 1
postProcessor {
1 = mail
1 {
recipientEmail = your@mail.com
senderEmail = your@mail.com
}
}
10 = TEXTLINE
10 {
type = text
name = email
placeholder = Email
label {
value = Email
}
}
20 = SUBMIT
20 {
type = submit
name = submit
value = Submit
}
rules {
1 = required
1 {
showMessage = 1
message = Required
error = This field is required
element = email
}
2 = email
2 {
showMessage = 0
message = (john.doe@domain.com)
error = This is not a valid email address
element = email
}
}
In my case it didn't work. Both messages are visible in label tag (see attached image).
Yes but this is the error message not the mandatory message. "Show message in label" only affects the mandatory messages.
- Description updated (diff)
;-) Thx. Now I understand. Sorry.
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
- Status changed from Resolved to Closed
Also available in: Atom
PDF