Reputation: 1488
I have a nested form using Cocoon. Within the nested form I have a select menu that I want to call chosen() on.
Normally I would have the following in the code
$('#cust_select').chosen()
However, I need to call this after a nested field has been added using something such as
$('#container').bind('cocoon:before-insert', function(e, inserted_item) {
// ... do something
});
However, I can't get this to work and so have 2 questions
any thoughts?
Michael
Upvotes: 0
Views: 1622
Reputation: 5515
1) The CoffeeScript version is:
$('#cust_select').chosen() # just the same
$('#container').bind 'cocoon:before-insert', (e, inserted_item) ->
# ... do something with the inserted item
2) inserted_item is indeed the inserted item:
From here
To listen to the events, you to have the following code in your javascript:
$('#container').bind('cocoon:before-insert', function(e, inserted_item) { // ... do something });
Where e is the event and the second parameter is the inserted or removed item. This allows you to change markup, or add effects/animations (see example below).
Upvotes: 1