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

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

Projects

None yet

3 participants

@ckip
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
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
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
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...

@mbrostami mbrostami referenced this issue Dec 9, 2016
Merged

Form validation some fixes #12466

3 of 3 tasks complete
@sergeyklay sergeyklay added this to the 3.0.3 milestone Dec 20, 2016
@sergeyklay
Collaborator

Fixed in the 3.0.x branch. Thanks you

@sergeyklay sergeyklay closed this Dec 20, 2016
@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