New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed bug in FormHelper::error() #9105
Conversation
In FormHelper::error(), param array $text doesn't work. Fixed it.
Please provide test case or example code to reproduce the issue. |
That changes switches $e with the rule identifier and not the error message. |
What does this fix? How does someone reproduce the issue you're having? |
I'm sorry for my little request message. I tried to use this param array $text for setting validation error message that was not setted in model. In CakePHP 2.x, default validation error message is rule name. So, the output is different in spite of the same param $text. For same output, you must: I suggest to fix it get same output with $text = [ 'rule name' => 'new error message' ]. Thank you. Example code: CakePHP 2.8: $ cat app/Controller/TestController.php
$ cat app/Model/Test.php
$ cat app/View/Test/a.ctp
result: debug( $this->Test->validationErrors ) outputs:
Form::error() outputs:
CakePHP 3.2: $ cat src/Controller/TestController.php
$ cat src/Model/Table/TestTable.php
$ cat src/Template/Test/a.ctp
result: debug( $Entity->errors() ) outputs:
Form::error() outputs:
|
Thanks for providing more context @oyas. This change causes a number of tests to fail which indicates that is it breaking existing behavior. It looks like the failing tests are preserving the current behavior that you'd like to change. Perhaps you could modify your changes to be compatible with allowing replacement by either the message, or the rule key? |
In param $text, you can set the rule key or the message for array key. The order of priority to apply is 1 rule key, 2 message.
foreach ($error as $k => $e) { | ||
if (isset($text[$k])) { | ||
$tmp[] = $text[$k]; | ||
} else if (isset($text[$e])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usage of ELSE IF is discouraged; use ELSEIF instead
Usage of ELSE IF not allowed; use ELSEIF instead
Would it be possible to get a test for the new behavior? |
I modified this change. This change is compatible with allowing replacement by either the message, or the rule key.
Example code: $ cat src/Template/Test/a.ctp
Form::error() outputs:
|
Current coverage is 94.93%@@ master #9105 diff @@
==========================================
Files 368 368
Lines 26989 26994 +5
Methods 3232 3232
Messages 0 0
Branches 0 0
==========================================
+ Hits 25624 25628 +4
- Misses 1365 1366 +1
Partials 0 0
|
More detail example: $ cat src/Template/Test/a.ctp
Form::error() outputs:
|
Thanks for the example code @oyas I can turn that into automated regression tests 😄 |
Thanks @oyas |
Thank you very much. |
In FormHelper::error(), param array $text doesn't work.
Fixed it.