Nested form field with JqueryIs there an “exists” function for jQuery?Add table row in jQueryHow do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How to check whether a checkbox is checked in jQuery?Convert form data to JavaScript object with jQueryDisable/enable an input with jQuery?How can I refresh a page with jQuery?jQuery scroll to element“Thinking in AngularJS” if I have a jQuery background?

How to befriend someone who doesn't like to talk?

How to represent jealousy in a cute way?

What is Gilligan's full Name?

ASCII Meme Arrow Generator

How does AFV select the winning videos?

Why do (or did, until very recently) aircraft transponders wait to be interrogated before broadcasting beacon signals?

Why is my power MOSFET heating up when on?

What is this object?

That's not my X, its Y is too Z

Why are ambiguous grammars bad?

What is the STRONGEST end-of-line knot to use if you want to use a steel-thimble at the end, so that you've got a steel-eyelet at the end of the line?

How to Handle Many Times Series Simultaneously?

Recording Spectral Lines at Home

What is this Amiga 2000 mod?

How can I find out about the game world without meta-influencing it?

My mom's return ticket is 3 days after I-94 expires

Mathematica 12 has gotten worse at solving simple equations?

How can I list the different hex characters between two files?

Should I be able to use the Gloom Stalker ranger's Dread Ambusher class feature when attacking before initiative has been rolled to add a d8 damage?

What is the theme of analysis?

Why do I seem to lose data using this bash pipe construction?

What is the "books received" section in journals?

How many sets of dice do I need for D&D?

How can powerful telekinesis avoid violating Newton's 3rd Law?



Nested form field with Jquery


Is there an “exists” function for jQuery?Add table row in jQueryHow do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How to check whether a checkbox is checked in jQuery?Convert form data to JavaScript object with jQueryDisable/enable an input with jQuery?How can I refresh a page with jQuery?jQuery scroll to element“Thinking in AngularJS” if I have a jQuery background?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a form where I'm loading nested fields. It works fine if I only have one div fields but if I have 2 of them for different form field types it doubles the request and it adds 2 field instead of 1. I tried to use the function .closest but it's not working at all



here is what I have






 $('form').on('click', '.add_fields', function(event) 
$(event.target).closest('.nested-form'), function(e)
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$('.fields').append($(this).data('fields').replace(regexp, time));
return e.preventDefault();
;
);





then inside my form I have






<div class="nested-form">
<div class="fields">
<div class="form-group">
<select name="user[talent_genres_attributes][0][genre]" id="user_talent_genres_attributes_0_genre">
<option value="Musicians">Musicians</option>
<option selected="selected" value="Acting">Acting</option>
<option value="Modeling">Modeling</option>
<option value="DJs">DJs</option></select>
</div>
</div>
</div>
<a class="add_fields btn btn-secondary" data-id="70350559861960" data-fields="<fieldset><div class='form-group'><select name=&quot;user[talent_genres_attributes][70350559861960][genre]&quot; id=&quot;user_talent_genres_attributes_70350559861960_genre&quot;><option value=&quot;Musicians&quot;>Musicians</option><option value=&quot;Acting&quot;>Acting</option><option value=&quot;Modeling&quot;>Modeling</option><option value=&quot;DJs&quot;>DJs</option></select><input as=&quot;hidden&quot; type=&quot;hidden&quot; value=&quot;false&quot; name=&quot;user[talent_genres_attributes][70350559861960][_destroy]&quot; id=&quot;user_talent_genres_attributes_70350559861960__destroy&quot; /><a class=&quot;remove_record btn btn-danger&quot; href=&quot;#&quot;>Delete</a></div></fieldset>" href="#">Add Genres</a>

<div class="nested-form">
<div class="fields">
<div class="form-group">
<select name="user[talent_genres_attributes][1][genre]" id="user_talent_genres_attributes_1_genre">
<option selected="selected" value="Musicians">Musicians</option>
<option value="Acting">Acting</option>
<option value="Modeling">Modeling</option>
<option value="DJs">DJs</option></select>
</div>
</div>
</div>
<a class="add_fields btn btn-secondary" data-id="70350580425060" data-fields="<fieldset><div class='form-group'><select name=&quot;user[talent_locations_attributes][70350580425060][location]&quot; id=&quot;user_talent_locations_attributes_70350580425060_location&quot;><option value=&quot;Los Angeles&quot;>Los Angeles</option><option value=&quot;Chicago&quot;>Chicago</option><option value=&quot;Detroit&quot;>Detroit</option><option value=&quot;Miami&quot;>Miami</option><option value=&quot;New York&quot;>New York</option><option value=&quot;San Francisco&quot;>San Francisco</option></select><input as=&quot;hidden&quot; type=&quot;hidden&quot; value=&quot;false&quot; name=&quot;user[talent_locations_attributes][70350580425060][_destroy]&quot; id=&quot;user_talent_locations_attributes_70350580425060__destroy&quot; /><a class=&quot;remove_record btn btn-danger&quot; href=&quot;#&quot;>Delete</a></div></fieldset>" href="#">Add Locations</a>





BTW this is the version I had before that added fields in both .fields div container






 $('form').on('click', '.add_fields', function(event) 
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$('.fields').append($(this).data('fields').replace(regexp, time));
return eevent.preventDefault();
);












share|improve this question



















  • 1





    are the nested-form and th a tags all siblings? if so, use prev() instead of closest()

    – arieljuod
    Mar 25 at 1:07






  • 1





    also $('.fields') returns both .fields divs, use something like $(this).find('.fields') to grab only the one inside that .nested-form div

    – arieljuod
    Mar 25 at 1:11


















0















I have a form where I'm loading nested fields. It works fine if I only have one div fields but if I have 2 of them for different form field types it doubles the request and it adds 2 field instead of 1. I tried to use the function .closest but it's not working at all



here is what I have






 $('form').on('click', '.add_fields', function(event) 
$(event.target).closest('.nested-form'), function(e)
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$('.fields').append($(this).data('fields').replace(regexp, time));
return e.preventDefault();
;
);





then inside my form I have






<div class="nested-form">
<div class="fields">
<div class="form-group">
<select name="user[talent_genres_attributes][0][genre]" id="user_talent_genres_attributes_0_genre">
<option value="Musicians">Musicians</option>
<option selected="selected" value="Acting">Acting</option>
<option value="Modeling">Modeling</option>
<option value="DJs">DJs</option></select>
</div>
</div>
</div>
<a class="add_fields btn btn-secondary" data-id="70350559861960" data-fields="<fieldset><div class='form-group'><select name=&quot;user[talent_genres_attributes][70350559861960][genre]&quot; id=&quot;user_talent_genres_attributes_70350559861960_genre&quot;><option value=&quot;Musicians&quot;>Musicians</option><option value=&quot;Acting&quot;>Acting</option><option value=&quot;Modeling&quot;>Modeling</option><option value=&quot;DJs&quot;>DJs</option></select><input as=&quot;hidden&quot; type=&quot;hidden&quot; value=&quot;false&quot; name=&quot;user[talent_genres_attributes][70350559861960][_destroy]&quot; id=&quot;user_talent_genres_attributes_70350559861960__destroy&quot; /><a class=&quot;remove_record btn btn-danger&quot; href=&quot;#&quot;>Delete</a></div></fieldset>" href="#">Add Genres</a>

<div class="nested-form">
<div class="fields">
<div class="form-group">
<select name="user[talent_genres_attributes][1][genre]" id="user_talent_genres_attributes_1_genre">
<option selected="selected" value="Musicians">Musicians</option>
<option value="Acting">Acting</option>
<option value="Modeling">Modeling</option>
<option value="DJs">DJs</option></select>
</div>
</div>
</div>
<a class="add_fields btn btn-secondary" data-id="70350580425060" data-fields="<fieldset><div class='form-group'><select name=&quot;user[talent_locations_attributes][70350580425060][location]&quot; id=&quot;user_talent_locations_attributes_70350580425060_location&quot;><option value=&quot;Los Angeles&quot;>Los Angeles</option><option value=&quot;Chicago&quot;>Chicago</option><option value=&quot;Detroit&quot;>Detroit</option><option value=&quot;Miami&quot;>Miami</option><option value=&quot;New York&quot;>New York</option><option value=&quot;San Francisco&quot;>San Francisco</option></select><input as=&quot;hidden&quot; type=&quot;hidden&quot; value=&quot;false&quot; name=&quot;user[talent_locations_attributes][70350580425060][_destroy]&quot; id=&quot;user_talent_locations_attributes_70350580425060__destroy&quot; /><a class=&quot;remove_record btn btn-danger&quot; href=&quot;#&quot;>Delete</a></div></fieldset>" href="#">Add Locations</a>





BTW this is the version I had before that added fields in both .fields div container






 $('form').on('click', '.add_fields', function(event) 
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$('.fields').append($(this).data('fields').replace(regexp, time));
return eevent.preventDefault();
);












share|improve this question



















  • 1





    are the nested-form and th a tags all siblings? if so, use prev() instead of closest()

    – arieljuod
    Mar 25 at 1:07






  • 1





    also $('.fields') returns both .fields divs, use something like $(this).find('.fields') to grab only the one inside that .nested-form div

    – arieljuod
    Mar 25 at 1:11














0












0








0








I have a form where I'm loading nested fields. It works fine if I only have one div fields but if I have 2 of them for different form field types it doubles the request and it adds 2 field instead of 1. I tried to use the function .closest but it's not working at all



here is what I have






 $('form').on('click', '.add_fields', function(event) 
$(event.target).closest('.nested-form'), function(e)
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$('.fields').append($(this).data('fields').replace(regexp, time));
return e.preventDefault();
;
);





then inside my form I have






<div class="nested-form">
<div class="fields">
<div class="form-group">
<select name="user[talent_genres_attributes][0][genre]" id="user_talent_genres_attributes_0_genre">
<option value="Musicians">Musicians</option>
<option selected="selected" value="Acting">Acting</option>
<option value="Modeling">Modeling</option>
<option value="DJs">DJs</option></select>
</div>
</div>
</div>
<a class="add_fields btn btn-secondary" data-id="70350559861960" data-fields="<fieldset><div class='form-group'><select name=&quot;user[talent_genres_attributes][70350559861960][genre]&quot; id=&quot;user_talent_genres_attributes_70350559861960_genre&quot;><option value=&quot;Musicians&quot;>Musicians</option><option value=&quot;Acting&quot;>Acting</option><option value=&quot;Modeling&quot;>Modeling</option><option value=&quot;DJs&quot;>DJs</option></select><input as=&quot;hidden&quot; type=&quot;hidden&quot; value=&quot;false&quot; name=&quot;user[talent_genres_attributes][70350559861960][_destroy]&quot; id=&quot;user_talent_genres_attributes_70350559861960__destroy&quot; /><a class=&quot;remove_record btn btn-danger&quot; href=&quot;#&quot;>Delete</a></div></fieldset>" href="#">Add Genres</a>

<div class="nested-form">
<div class="fields">
<div class="form-group">
<select name="user[talent_genres_attributes][1][genre]" id="user_talent_genres_attributes_1_genre">
<option selected="selected" value="Musicians">Musicians</option>
<option value="Acting">Acting</option>
<option value="Modeling">Modeling</option>
<option value="DJs">DJs</option></select>
</div>
</div>
</div>
<a class="add_fields btn btn-secondary" data-id="70350580425060" data-fields="<fieldset><div class='form-group'><select name=&quot;user[talent_locations_attributes][70350580425060][location]&quot; id=&quot;user_talent_locations_attributes_70350580425060_location&quot;><option value=&quot;Los Angeles&quot;>Los Angeles</option><option value=&quot;Chicago&quot;>Chicago</option><option value=&quot;Detroit&quot;>Detroit</option><option value=&quot;Miami&quot;>Miami</option><option value=&quot;New York&quot;>New York</option><option value=&quot;San Francisco&quot;>San Francisco</option></select><input as=&quot;hidden&quot; type=&quot;hidden&quot; value=&quot;false&quot; name=&quot;user[talent_locations_attributes][70350580425060][_destroy]&quot; id=&quot;user_talent_locations_attributes_70350580425060__destroy&quot; /><a class=&quot;remove_record btn btn-danger&quot; href=&quot;#&quot;>Delete</a></div></fieldset>" href="#">Add Locations</a>





BTW this is the version I had before that added fields in both .fields div container






 $('form').on('click', '.add_fields', function(event) 
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$('.fields').append($(this).data('fields').replace(regexp, time));
return eevent.preventDefault();
);












share|improve this question
















I have a form where I'm loading nested fields. It works fine if I only have one div fields but if I have 2 of them for different form field types it doubles the request and it adds 2 field instead of 1. I tried to use the function .closest but it's not working at all



here is what I have






 $('form').on('click', '.add_fields', function(event) 
$(event.target).closest('.nested-form'), function(e)
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$('.fields').append($(this).data('fields').replace(regexp, time));
return e.preventDefault();
;
);





then inside my form I have






<div class="nested-form">
<div class="fields">
<div class="form-group">
<select name="user[talent_genres_attributes][0][genre]" id="user_talent_genres_attributes_0_genre">
<option value="Musicians">Musicians</option>
<option selected="selected" value="Acting">Acting</option>
<option value="Modeling">Modeling</option>
<option value="DJs">DJs</option></select>
</div>
</div>
</div>
<a class="add_fields btn btn-secondary" data-id="70350559861960" data-fields="<fieldset><div class='form-group'><select name=&quot;user[talent_genres_attributes][70350559861960][genre]&quot; id=&quot;user_talent_genres_attributes_70350559861960_genre&quot;><option value=&quot;Musicians&quot;>Musicians</option><option value=&quot;Acting&quot;>Acting</option><option value=&quot;Modeling&quot;>Modeling</option><option value=&quot;DJs&quot;>DJs</option></select><input as=&quot;hidden&quot; type=&quot;hidden&quot; value=&quot;false&quot; name=&quot;user[talent_genres_attributes][70350559861960][_destroy]&quot; id=&quot;user_talent_genres_attributes_70350559861960__destroy&quot; /><a class=&quot;remove_record btn btn-danger&quot; href=&quot;#&quot;>Delete</a></div></fieldset>" href="#">Add Genres</a>

<div class="nested-form">
<div class="fields">
<div class="form-group">
<select name="user[talent_genres_attributes][1][genre]" id="user_talent_genres_attributes_1_genre">
<option selected="selected" value="Musicians">Musicians</option>
<option value="Acting">Acting</option>
<option value="Modeling">Modeling</option>
<option value="DJs">DJs</option></select>
</div>
</div>
</div>
<a class="add_fields btn btn-secondary" data-id="70350580425060" data-fields="<fieldset><div class='form-group'><select name=&quot;user[talent_locations_attributes][70350580425060][location]&quot; id=&quot;user_talent_locations_attributes_70350580425060_location&quot;><option value=&quot;Los Angeles&quot;>Los Angeles</option><option value=&quot;Chicago&quot;>Chicago</option><option value=&quot;Detroit&quot;>Detroit</option><option value=&quot;Miami&quot;>Miami</option><option value=&quot;New York&quot;>New York</option><option value=&quot;San Francisco&quot;>San Francisco</option></select><input as=&quot;hidden&quot; type=&quot;hidden&quot; value=&quot;false&quot; name=&quot;user[talent_locations_attributes][70350580425060][_destroy]&quot; id=&quot;user_talent_locations_attributes_70350580425060__destroy&quot; /><a class=&quot;remove_record btn btn-danger&quot; href=&quot;#&quot;>Delete</a></div></fieldset>" href="#">Add Locations</a>





BTW this is the version I had before that added fields in both .fields div container






 $('form').on('click', '.add_fields', function(event) 
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$('.fields').append($(this).data('fields').replace(regexp, time));
return eevent.preventDefault();
);








 $('form').on('click', '.add_fields', function(event) 
$(event.target).closest('.nested-form'), function(e)
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$('.fields').append($(this).data('fields').replace(regexp, time));
return e.preventDefault();
;
);





 $('form').on('click', '.add_fields', function(event) 
$(event.target).closest('.nested-form'), function(e)
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$('.fields').append($(this).data('fields').replace(regexp, time));
return e.preventDefault();
;
);





<div class="nested-form">
<div class="fields">
<div class="form-group">
<select name="user[talent_genres_attributes][0][genre]" id="user_talent_genres_attributes_0_genre">
<option value="Musicians">Musicians</option>
<option selected="selected" value="Acting">Acting</option>
<option value="Modeling">Modeling</option>
<option value="DJs">DJs</option></select>
</div>
</div>
</div>
<a class="add_fields btn btn-secondary" data-id="70350559861960" data-fields="<fieldset><div class='form-group'><select name=&quot;user[talent_genres_attributes][70350559861960][genre]&quot; id=&quot;user_talent_genres_attributes_70350559861960_genre&quot;><option value=&quot;Musicians&quot;>Musicians</option><option value=&quot;Acting&quot;>Acting</option><option value=&quot;Modeling&quot;>Modeling</option><option value=&quot;DJs&quot;>DJs</option></select><input as=&quot;hidden&quot; type=&quot;hidden&quot; value=&quot;false&quot; name=&quot;user[talent_genres_attributes][70350559861960][_destroy]&quot; id=&quot;user_talent_genres_attributes_70350559861960__destroy&quot; /><a class=&quot;remove_record btn btn-danger&quot; href=&quot;#&quot;>Delete</a></div></fieldset>" href="#">Add Genres</a>

<div class="nested-form">
<div class="fields">
<div class="form-group">
<select name="user[talent_genres_attributes][1][genre]" id="user_talent_genres_attributes_1_genre">
<option selected="selected" value="Musicians">Musicians</option>
<option value="Acting">Acting</option>
<option value="Modeling">Modeling</option>
<option value="DJs">DJs</option></select>
</div>
</div>
</div>
<a class="add_fields btn btn-secondary" data-id="70350580425060" data-fields="<fieldset><div class='form-group'><select name=&quot;user[talent_locations_attributes][70350580425060][location]&quot; id=&quot;user_talent_locations_attributes_70350580425060_location&quot;><option value=&quot;Los Angeles&quot;>Los Angeles</option><option value=&quot;Chicago&quot;>Chicago</option><option value=&quot;Detroit&quot;>Detroit</option><option value=&quot;Miami&quot;>Miami</option><option value=&quot;New York&quot;>New York</option><option value=&quot;San Francisco&quot;>San Francisco</option></select><input as=&quot;hidden&quot; type=&quot;hidden&quot; value=&quot;false&quot; name=&quot;user[talent_locations_attributes][70350580425060][_destroy]&quot; id=&quot;user_talent_locations_attributes_70350580425060__destroy&quot; /><a class=&quot;remove_record btn btn-danger&quot; href=&quot;#&quot;>Delete</a></div></fieldset>" href="#">Add Locations</a>





<div class="nested-form">
<div class="fields">
<div class="form-group">
<select name="user[talent_genres_attributes][0][genre]" id="user_talent_genres_attributes_0_genre">
<option value="Musicians">Musicians</option>
<option selected="selected" value="Acting">Acting</option>
<option value="Modeling">Modeling</option>
<option value="DJs">DJs</option></select>
</div>
</div>
</div>
<a class="add_fields btn btn-secondary" data-id="70350559861960" data-fields="<fieldset><div class='form-group'><select name=&quot;user[talent_genres_attributes][70350559861960][genre]&quot; id=&quot;user_talent_genres_attributes_70350559861960_genre&quot;><option value=&quot;Musicians&quot;>Musicians</option><option value=&quot;Acting&quot;>Acting</option><option value=&quot;Modeling&quot;>Modeling</option><option value=&quot;DJs&quot;>DJs</option></select><input as=&quot;hidden&quot; type=&quot;hidden&quot; value=&quot;false&quot; name=&quot;user[talent_genres_attributes][70350559861960][_destroy]&quot; id=&quot;user_talent_genres_attributes_70350559861960__destroy&quot; /><a class=&quot;remove_record btn btn-danger&quot; href=&quot;#&quot;>Delete</a></div></fieldset>" href="#">Add Genres</a>

<div class="nested-form">
<div class="fields">
<div class="form-group">
<select name="user[talent_genres_attributes][1][genre]" id="user_talent_genres_attributes_1_genre">
<option selected="selected" value="Musicians">Musicians</option>
<option value="Acting">Acting</option>
<option value="Modeling">Modeling</option>
<option value="DJs">DJs</option></select>
</div>
</div>
</div>
<a class="add_fields btn btn-secondary" data-id="70350580425060" data-fields="<fieldset><div class='form-group'><select name=&quot;user[talent_locations_attributes][70350580425060][location]&quot; id=&quot;user_talent_locations_attributes_70350580425060_location&quot;><option value=&quot;Los Angeles&quot;>Los Angeles</option><option value=&quot;Chicago&quot;>Chicago</option><option value=&quot;Detroit&quot;>Detroit</option><option value=&quot;Miami&quot;>Miami</option><option value=&quot;New York&quot;>New York</option><option value=&quot;San Francisco&quot;>San Francisco</option></select><input as=&quot;hidden&quot; type=&quot;hidden&quot; value=&quot;false&quot; name=&quot;user[talent_locations_attributes][70350580425060][_destroy]&quot; id=&quot;user_talent_locations_attributes_70350580425060__destroy&quot; /><a class=&quot;remove_record btn btn-danger&quot; href=&quot;#&quot;>Delete</a></div></fieldset>" href="#">Add Locations</a>





 $('form').on('click', '.add_fields', function(event) 
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$('.fields').append($(this).data('fields').replace(regexp, time));
return eevent.preventDefault();
);





 $('form').on('click', '.add_fields', function(event) 
var regexp, time;
time = new Date().getTime();
regexp = new RegExp($(this).data('id'), 'g');
$('.fields').append($(this).data('fields').replace(regexp, time));
return eevent.preventDefault();
);






jquery ruby-on-rails






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 23:30







Marrento

















asked Mar 24 at 23:11









MarrentoMarrento

174112




174112







  • 1





    are the nested-form and th a tags all siblings? if so, use prev() instead of closest()

    – arieljuod
    Mar 25 at 1:07






  • 1





    also $('.fields') returns both .fields divs, use something like $(this).find('.fields') to grab only the one inside that .nested-form div

    – arieljuod
    Mar 25 at 1:11













  • 1





    are the nested-form and th a tags all siblings? if so, use prev() instead of closest()

    – arieljuod
    Mar 25 at 1:07






  • 1





    also $('.fields') returns both .fields divs, use something like $(this).find('.fields') to grab only the one inside that .nested-form div

    – arieljuod
    Mar 25 at 1:11








1




1





are the nested-form and th a tags all siblings? if so, use prev() instead of closest()

– arieljuod
Mar 25 at 1:07





are the nested-form and th a tags all siblings? if so, use prev() instead of closest()

– arieljuod
Mar 25 at 1:07




1




1





also $('.fields') returns both .fields divs, use something like $(this).find('.fields') to grab only the one inside that .nested-form div

– arieljuod
Mar 25 at 1:11






also $('.fields') returns both .fields divs, use something like $(this).find('.fields') to grab only the one inside that .nested-form div

– arieljuod
Mar 25 at 1:11













1 Answer
1






active

oldest

votes


















0














I typically do something along the lines of:



<div id='fields_area'></div>



Then use $('#fields_area').append('.fields_container'); to add fields



and $(this).closest('.fields_container').remove(); (triggered by a button in .fields_container) to remove fields.



Wrap your data-* in a <div class="fields_container"></div> and this should do it.



Edit: Checkout cocoon : https://github.com/nathanvda/cocoon






share|improve this answer























  • I ended up using cocoon and looking into the source code to see how it was compared to wha I had done.

    – Marrento
    Mar 25 at 22:07











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329472%2fnested-form-field-with-jquery%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I typically do something along the lines of:



<div id='fields_area'></div>



Then use $('#fields_area').append('.fields_container'); to add fields



and $(this).closest('.fields_container').remove(); (triggered by a button in .fields_container) to remove fields.



Wrap your data-* in a <div class="fields_container"></div> and this should do it.



Edit: Checkout cocoon : https://github.com/nathanvda/cocoon






share|improve this answer























  • I ended up using cocoon and looking into the source code to see how it was compared to wha I had done.

    – Marrento
    Mar 25 at 22:07















0














I typically do something along the lines of:



<div id='fields_area'></div>



Then use $('#fields_area').append('.fields_container'); to add fields



and $(this).closest('.fields_container').remove(); (triggered by a button in .fields_container) to remove fields.



Wrap your data-* in a <div class="fields_container"></div> and this should do it.



Edit: Checkout cocoon : https://github.com/nathanvda/cocoon






share|improve this answer























  • I ended up using cocoon and looking into the source code to see how it was compared to wha I had done.

    – Marrento
    Mar 25 at 22:07













0












0








0







I typically do something along the lines of:



<div id='fields_area'></div>



Then use $('#fields_area').append('.fields_container'); to add fields



and $(this).closest('.fields_container').remove(); (triggered by a button in .fields_container) to remove fields.



Wrap your data-* in a <div class="fields_container"></div> and this should do it.



Edit: Checkout cocoon : https://github.com/nathanvda/cocoon






share|improve this answer













I typically do something along the lines of:



<div id='fields_area'></div>



Then use $('#fields_area').append('.fields_container'); to add fields



and $(this).closest('.fields_container').remove(); (triggered by a button in .fields_container) to remove fields.



Wrap your data-* in a <div class="fields_container"></div> and this should do it.



Edit: Checkout cocoon : https://github.com/nathanvda/cocoon







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 18:20









Richard LegacyRichard Legacy

816




816












  • I ended up using cocoon and looking into the source code to see how it was compared to wha I had done.

    – Marrento
    Mar 25 at 22:07

















  • I ended up using cocoon and looking into the source code to see how it was compared to wha I had done.

    – Marrento
    Mar 25 at 22:07
















I ended up using cocoon and looking into the source code to see how it was compared to wha I had done.

– Marrento
Mar 25 at 22:07





I ended up using cocoon and looking into the source code to see how it was compared to wha I had done.

– Marrento
Mar 25 at 22:07



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329472%2fnested-form-field-with-jquery%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript