mirror of
https://0xacab.org/sutty/sutty
synced 2025-02-22 22:21:49 +00:00
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
![]() |
$(document).on('turbolinks:load', function() {
|
||
|
$('.add-group').click(function(e) {
|
||
|
e.preventDefault();
|
||
|
|
||
|
var _this = $(this);
|
||
|
var _groups = _this.parents('.field-groups');
|
||
|
var _extra = _groups.children('.extra-groups');
|
||
|
var _group_orig = _groups
|
||
|
.children('.field-group')
|
||
|
.first();
|
||
|
|
||
|
_group_orig.find('select.select2').select2('destroy');
|
||
|
var _group = _group_orig
|
||
|
.clone()
|
||
|
.appendTo(_extra);
|
||
|
|
||
|
// Encontrar todos los elementos con '[0]' en el nombre.
|
||
|
var _date = (new Date).getTime();
|
||
|
_group.find('[name*="[0]"]').each(function(i, input) {
|
||
|
var _input = $(input);
|
||
|
var _name = _input.attr('name');
|
||
|
_input.attr('name', _name.replace(/\[0\]/, `[${_date}]`));
|
||
|
_input.val('');
|
||
|
});
|
||
|
|
||
|
_group.find('.remove-group').click(function(e) {
|
||
|
e.preventDefault();
|
||
|
|
||
|
var _this = $(this);
|
||
|
var _group = _this.parents('.field-group').remove();
|
||
|
});
|
||
|
|
||
|
var _select2 = _group.find('.select2');
|
||
|
var _select2_opts = { theme: 'bootstrap', width: '' }
|
||
|
_select2.select2(_select2_opts);
|
||
|
_group_orig.find('.select2').select2(_select2_opts);
|
||
|
});
|
||
|
});
|