Question

I've been learning how to use ZF2 from the book Learn ZF2: Learning by Example by Slavey Karadzhov. In it, he shows how to build forms using annotations. One particularly helpful feature is the "pattern" attribute. If you add a pattern to the form, there's a really cool JavaScript function that checks does client-side validation. If a field's input doesn't match the desired pattern, a groovy little tooltip of sorts pops up pointing out the field(s) that have problems and telling you what needs to be fixed.

I was wondering: is there a similar system in ZF2 so that, when a field is highlighted, a similar tooltip pops up to give hints on what exactly needs to be entered into a field? For example, for a password field it could give the requirements for the password. And if this isn't built in, is there a module out there somewhere that does this? I've done a bunch of Googling on this subject, but I've come up empty so far.

Was it helpful?

Solution

Since zf2 come's with an Twitter Bootstrap implementation you could just use the Tooltip functionality. I personally do not use anotation's in my forms for various reasons, one being the performance hit you take.

within your YourForm.php just set some data attributes and you should be good to go:

$this->add(array(
        'name'       => 'submit',
        'type'       => 'Submit',
        'attributes' => array(
            'value'          => 'Save',
            'id'             => 'submitbutton',
            'data-toggle'    => 'tooltip',
            'data-placement' => 'left',
            'title'          => 'Press me I am a button :D',
            ),
        ));

The annotation equivalent would be:

* @Annotation\Attributes({"data-toggle":"tooltip", "data-placement":"left", "title":"Press me I am a button :D"})

OTHER TIPS

don't forget to initialize

$(function () {
  $('[data-toggle="tooltip"]').tooltip();
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top