Sha256: db7c1c34e637e2444bb29b37f6e4084b97800666a5ca6a140450226759b44765
Contents?: true
Size: 1.28 KB
Versions: 3
Compression:
Stored size: 1.28 KB
Contents
//= require spree/backend $(document).on('click', '.js-remove-row', function () { var $removeLink = $(this); var $row = $removeLink.closest('.row'); var destroyName = $removeLink.data('row-object-name') + '[_destroy]'; $row.replaceWith( '<input type="hidden" name="' + destroyName + '" value="1" />'); return false; }); $(document).on('click', '.js-duplicate-last-row', function () { var $duplicateLink = $(this); var $row = $duplicateLink.prev(); var reRowId = /\[([0-9]+)\]/; var rowId = parseInt(reRowId.exec($row.find('[name]:first').attr('name'))[1], 10); var newRowId = rowId + 1; var $duplicateRow = $row.clone(); $duplicateRow.find('[for]').each(function () { var labelFor = $(this).attr('for'); $(this).attr('for', labelFor.replace('_' + rowId + '_', '_' + newRowId + '_')); }); $duplicateRow.find('[name]').each(function () { var name = $(this).attr('name'); var id = $(this).attr('id'); $(this).attr('id', id.replace('_' + rowId + '_', '_' + newRowId + '_')); $(this).attr('name', name.replace(reRowId, '[' + newRowId + ']')); }); $duplicateRow.find('.select2-container').remove(); $duplicateLink.before($duplicateRow); $('select.select2').select2({ allowClear: true, dropdownAutoWidth: true }); return false; });
Version data entries
3 entries across 3 versions & 1 rubygems