You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 12, 2021. It is now read-only.
The error message is shown next to the element, but the whole div.control-group does not have class "error" added to it.
Es far as I can see this is for the following reasons:
Performing addError on an element marks the element as invalid, but you would have to call the parent's form isValid() again in order to set the whole form invalid.
In the class EasyBib_Form in function "buildBootstrapErrorDecorators" only the forms getErrors() are handled. But a custom error message added with element->addError() will not be returned by this.
Here is my current workaround:
Step 1
After I call $formName->getElement('elementName')->addError('Error message'), I call $form->buildBootstrapErrorDecorators();
This funtion is otherwise only called in EasyBib_Form's function "isValid", which calls "isValid()" of the parent class. But that seems to reset all error messages (as far as I can see), and only validates against the validators. The form would be valid again and "buildBootstrapErrorDecorators()" would not be performed.
Step2
In "buildBootstrapErrorDecorators" I add:
foreach ($this->getElements() AS $element)
if (count($element->getErrorMessages()) > 0) {
$htmlTagDecorator = $element->getDecorator('HtmlTag');
if (empty($htmlTagDecorator)) {
continue;
}
$class = $htmlTagDecorator->getOption('class');
$htmlTagDecorator->setOption('class', $class . ' error');
}
I hope it is quite understandable what my problem is, and hopefully my (or a better) solution for this will be implemented. If I just missed something and am totally wrong, and if what I want could be achieved otherwise, I apologize and kinldy ask for a hint into the right direction.
Best regards
Christian
The text was updated successfully, but these errors were encountered:
thank you very much for the great problem analysis :)
Liked it very much to read and follow it!
Yeah, Zend_Form and Error handling is at some points really strange and behaves not like expected.
Don't know, why adding an error doesn't result in a form error.
I remember checking the Zend_Form code and some blog posts about it - didnt find any clear solution how to add an error manually.
So, no, I have no better solution than you have right now.
We could integrate your solution by pull-request!
Hello,
in a controller script I use the follwoing code to add an error message to a form's element:
The error message is shown next to the element, but the whole div.control-group does not have class "error" added to it.
Es far as I can see this is for the following reasons:
Here is my current workaround:
Step 1
After I call
$formName->getElement('elementName')->addError('Error message')
, I call$form->buildBootstrapErrorDecorators();
This funtion is otherwise only called in EasyBib_Form's function "isValid", which calls "isValid()" of the parent class. But that seems to reset all error messages (as far as I can see), and only validates against the validators. The form would be valid again and "buildBootstrapErrorDecorators()" would not be performed.
Step2
In "buildBootstrapErrorDecorators" I add:
I hope it is quite understandable what my problem is, and hopefully my (or a better) solution for this will be implemented. If I just missed something and am totally wrong, and if what I want could be achieved otherwise, I apologize and kinldy ask for a hint into the right direction.
Best regards
Christian
The text was updated successfully, but these errors were encountered: