-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Form validation some fixes #12466
Form validation some fixes #12466
Conversation
|
||
if !(validation instanceof Validation) { | ||
// Create an implicit validation | ||
validation = new Validation(); |
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.
The let
statement is used to mutate variables, properties and arrays. Variables are by default immutable and this instruction makes them mutable:
let validation = new Validation();
|
||
let validation = this->getValidation(); | ||
|
||
if !(validation instanceof Validation) { |
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.
here does not need braces
for elementMessage in messages { | ||
this->get(elementMessage->getField())->appendMessage(elementMessage); | ||
} | ||
validationStatus = false; |
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.
let validationStatus = false;
b4e9364
to
16f36ac
Compare
|
||
if !(validation instanceof Validation) { | ||
// Create an implicit validation | ||
let validation = new Validation(); |
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.
Well, I think I misled you. The exclamation point has a higher priority. So you should use:
if !(validation instanceof Validation) {
But actually I think that more flexibility was to use the interface but not concrete class
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.
Yeah! You're right. Thanks for comments.
2919cda
to
ce6440b
Compare
if typeof messages != "array" { | ||
return new Group(); | ||
} | ||
return messages; |
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.
I think, returning multiple type of value is not a good idea (see line 378 old - return type).
@mbrostami Could you please split this PR into parts: one that can be merged to the Thanks |
@@ -712,7 +684,11 @@ class Form extends Injectable implements \Countable, \Iterator | |||
public function rewind() -> void | |||
{ | |||
let this->_position = 0; | |||
let this->_elementsIndexed = array_values(this->_elements); |
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.
If you create a form without any element, and iterate that, php warning will be shown, because this->_elements is null. I added some code to prevent that. https://github.com/phalcon/cphalcon/blob/3.0.x/tests/unit/Forms/FormTest.php#L77
I think using _messages as a single type (Group|null) would be better, and will avoid of complexity. |
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.
Cc: @niden @andresgutierrez Could you please take a look
@mbrostami Could you please rebase, update CHANGELOG.md and cover issues by small test you successfully solved |
@sergeyklay Sure. |
e43345e
to
0d43455
Compare
@sergeyklay can you please check appveyor error? Is it my bad!? |
|
This issue (#12395) will also be fixed by this PR. |
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.
Could you please take a look at comment for getMessagesFor
and update CHANGELOG.md by adding last issue.
Thanks
this->_messages[name] = group; | ||
|
||
return group; | ||
return this->get(name)->getMessages(); |
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.
Well, in general looks good to me. But it bothers me that previously this method always returned the Group
but now it can throw Exception. I think this behaviour should be the same now.
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.
Right, It should be backward compatible, I missed that.
@sergeyklay It's ready. |
@mbrostami Could you please rebase onto |
146549a
to
6082da3
Compare
@sergeyklay Done |
Squash please. |
Thanks |
Hello!
Form setValidation is not work correctly #12465
[2.1.x] $form->isValid() doesn't merge validators (separate Validation class) #11500
Form validation for field not possible #11135
Phalcon\Forms\Element hasMessages() always returns false #3167
In raising this pull request, I confirm the following (please check boxes):
Small description of change:
setValidation for form is not work correctly as I explained at #12465.
Elements messages doesn't set if custom validation fails.
Thanks