I have a nested form in a form, which on clicking on a button adds a bunch of fields for the user to complete.
At the moment, when the user clicks on it, I sum to a variable that tracks the amount of fields added. On the bunch of things added I add a button to remove them (a link_to_remove from the nested_form gem). I want to have an action on click on the remove button, BUT for some reason it is not activating it.
Here's the code on the view:
= f.fields_for :guests do |guest_form|
(...)
= guest_form.link_to_remove t('actions.delete'), class: 'flex button button-general btn red-button delete-client-button form-rate delete-room-button', method: 'get'
= f.link_to_add ((fa_stacked_icon "plus", base: "circle-thin", class: 'button-icon') + t('reservations.new.add_client')), :guests, class: 'button btn button-general green-button add-button new-client-button'
Here's my javascript:
$('.delete-client-button').click(function() {
do something...
});
But it is not doing anything.
You have to delegate the element
$('body').on('click', '.delete-client-button', function() {
do something...
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.