Skip to content
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

Phalcon\Forms\Element hasMessages() always returns false #3167

Closed
ckip opened this issue Dec 28, 2014 · 4 comments
Closed

Phalcon\Forms\Element hasMessages() always returns false #3167

ckip opened this issue Dec 28, 2014 · 4 comments
Assignees
Milestone

Comments

@ckip
Copy link

ckip commented Dec 28, 2014

Should these 2 lines of code return the same value ?

  1. $form->hasMessagesFor('name');
  2. $form->get('name')->hasMessages();

Before validation both these lines return false. But when the form validation fails, the first line returns true (which is good) while the second line still return false.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@olivier-monaco
Copy link
Contributor

The isValid form's method calls validators on each element, save messages in its own message list and does not propagate messages to each element.

Before rendering my elements, I use the following workaround:

foreach ($form->getMessagesFor($this->getName()) as $message) {
    $this->appendMessage($message);
}

@ckip
Copy link
Author

ckip commented Dec 29, 2014

Thank you. I can see why that workaround would work, but I don't see the added benefit.
I'd much rather use hasMessagesFor() if It's not possible to get individual messages.

@olivier-monaco
Copy link
Contributor

You can. I don't want to depend on forms so I don't.

I don't use the rendering behavior included with Phalcon. I use Bootstrap for UI. Sometimes I use complex forms (with columns and responsive). Sometimes I use element alone (ex. short inline form like search field).

My way to do is to have a "view helper" that can render an element depending on is type (select, checkbox, text input, email input...). It generates a "form-control" div (cf. http://getbootstrap.com/css/#forms) including "help text", "validation text", "input group", etc.

So I need to have messages on the element.

This is my way and I may be wrong...

@sergeyklay sergeyklay added this to the 3.0.3 milestone Dec 20, 2016
@sergeyklay
Copy link
Contributor

Fixed in the 3.0.x branch. Thanks you

@sergeyklay sergeyklay self-assigned this Dec 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants