Add jquery event on edit form

606 views
Skip to first unread message

fran

unread,
May 10, 2012, 7:46:14 AM5/10/12
to sonata...@googlegroups.com
Hi,

I am almost new to Sonata Admin.

I would like to add some javascript code on fields that are present on edit form.

However, the id attribute of the input field change on each request (based upon the uniqid) :

<input type="text" id="s4fab9edbc0783_libelle" class="sonata-medium" value="" />

I would like to add this kind of code (not really this code but it is not important) :
$('#s4fab9edbc0783_libelle').change(function() {
  alert('Handler for .change() called.');
});

What is the better way to do this kind of thing ?
 * Get the form action and parse the url to get uniqid parameters ? Not sure that it is a good idea.
 * Change the Twig for this field and add onChange attribute ?
 * ...

Thanks for your answers,
Fran'

r1pp3rj4ck

unread,
May 10, 2012, 7:53:26 AM5/10/12
to sonata...@googlegroups.com
You can get the id of a field somehow afaik.

Thomas Rabaix

unread,
May 10, 2012, 6:17:14 PM5/10/12
to sonata...@googlegroups.com
There is no solution to get the id as the value change unless to set a constant uniqid in the Admin Class, however this will lead to some random error on some edge case. You can also consider using a class instead of an id to add custom behavior.

--
You received this message because you are subscribed to the Google Groups "sonata-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sonata-users/-/DFc3UO_G5h8J.

To post to this group, send email to sonata...@googlegroups.com.
To unsubscribe from this group, send email to sonata-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sonata-users?hl=en.



--
Thomas Rabaix
http://rabaix.net | http://sonata-project.org

fran

unread,
May 11, 2012, 3:07:21 AM5/11/12
to sonata...@googlegroups.com


On Thursday, May 10, 2012 11:17:14 PM UTC+1, Thomas Rabaix wrote:
There is no solution to get the id as the value change unless to set a constant uniqid in the Admin Class, however this will lead to some random error on some edge case. You can also consider using a class instead of an id to add custom behavior.


Thanks for your answer.

Fran

Reply all
Reply to author
Forward
0 new messages