I’m very new to JavaScript in general so having trouble with this. Working with Rails / jQuery / CoffeeScript. I’m adding a bulk add option to a form. The bulk add works however I’m also trying to save any fields that were manually filled. This is the code I have so far:
window.insert_bulk_fields = (text)->
site = $('#website_link').val()
links = text.split('\n').join('&links[]=').replace(/\s+/g, '')
input_links = $("input[type=text][id^='website_rentals_attributes']").val()
other_links = '&links[]=' + input_links.split(',').join('&links[]=')
window.location.href = './new?links[]=' + links + other_links + '&site=' + site
Everything works except for
input_links = $("input[type=text][id^='website_rentals_attributes']").val()
which is only returning the first instance rather than an array of all those fields.
I’ve gone through similar questions on stackoverflow but I can’t make this work.
You should use map() for this as you are dealing with a collection