简体   繁体   中英

How to add two fields instead of one on click of link to add fields in nested form?

I have used gem 'nested_form', '~> 0.3.2' with rails 4, i have to add two fields on click of link_to_add helper method of nested form? How will i customize the javascript of nested form to add for this specific scenario?

I did this using jQuery:

$(document).on('nested:fieldAdded', function(event) {
    for (var n = 1; n; n--) {
        if ($('.fields').length < 2) {
            event.field.clone().insertAfter(event.field);
        }
    }
});

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM