We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to add JS for input fields?

its soo good that we can set input fields and Phalcon generated that. Its even good that I can attach classes too. But this time I want to attach javascrpt, e.g. "onclick" even. How to?



9.8k
edited Nov '15

you could do in volt or else something like this:
{{ text_area("aaaaaa", 'class': "form-control", "onclick":"alert('test')") }} It worked for me :)

By the way. As far as i know it is not necessary good to use such attributes like style or onevent (onclick) on any html elements. It is rather better to do javascript in extended files and that they are loaded at the and of the page and if possible in as few scripts as possible (faster page loading).

You shouldnt use onclick imho. Use addEventListener.