In fact, I do not see where it should be a decorator or view helper or script view.
If I wanted to attach some client-side behavior to the form element, I would probably set the attribute with $elt->setAttrib('class', 'someClass') or $elt->setAttrib('id', 'someId') , some hook that my script can connect to. Then I add listeners / handlers to these target elements.
For example, for a click handler using jQuery, it would be something like this:
(function($){ $(document).ready(function(){ $('.someClass').click(function(e){
The advantage is that it is unobtrusive, so the layout remains clean. I hope javascript is an improvement, not a critical part of the functionality, so it degrades competently.
Perhaps you mean that this javascript segment should be reused for different element identifiers - someClass in this example. In this case, you can simply write a view helper that takes the CSS class name as a parameter.
source share