From 5267a40f31927b37caa6f5d8fc88cba0ab2a02c0 Mon Sep 17 00:00:00 2001 From: Ali Lozano Date: Sun, 27 Nov 2016 23:01:07 -0500 Subject: [PATCH] Links changed by buttons - Fixed #122 Buttons has different styles of links, this could break the presentation layer. --- src/jquery.formset.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/jquery.formset.js b/src/jquery.formset.js index 9957b77..edbe07d 100644 --- a/src/jquery.formset.js +++ b/src/jquery.formset.js @@ -58,25 +58,25 @@ if (row.is('TR')) { // If the forms are laid out in table rows, insert // the remove button into the last table cell: - row.children(':last').append('' + options.deleteText + ''); + row.children(':last').append(''); } else if (row.is('UL') || row.is('OL')) { // If they're laid out as an ordered/unordered list, // insert an
  • after the last list item: - row.append('
  • ' + options.deleteText +'
  • '); + row.append('
  • '); } else { // Otherwise, just insert the remove button as the // last child element of the form's container: - row.append('' + options.deleteText +''); + row.append(''); } // Check if we're under the minimum number of forms - not to display delete link at rendering if (!showDeleteLinks()){ - row.find('a.' + delCssSelector).hide(); + row.find('button.' + delCssSelector).hide(); } - row.find('a.' + delCssSelector).click(function() { + row.find('button.' + delCssSelector).click(function() { var row = $(this).parents('.' + options.formCssClass), del = row.find('input:hidden[id $= "-DELETE"]'), - buttonRow = row.siblings("a." + addCssSelector + ', .' + options.formCssClass + '-add'), + buttonRow = row.siblings("button." + addCssSelector + ', .' + options.formCssClass + '-add'), forms; if (del.length) { // We're dealing with an inline formset. @@ -104,7 +104,7 @@ } // Check if we've reached the minimum number of forms - hide all delete link(s) if (!showDeleteLinks()){ - $('a.' + delCssSelector).each(function(){$(this).hide();}); + $('button.' + delCssSelector).each(function(){$(this).hide();}); } // Check if we need to show the add button: if (buttonRow.is(':hidden') && showAddButton()) buttonRow.show(); @@ -177,14 +177,14 @@ // If forms are laid out as table rows, insert the // "add" button in a new table row: var numCols = $$.eq(0).children().length, // This is a bit of an assumption :| - buttonRow = $('' + options.addText + '') + buttonRow = $('') .addClass(options.formCssClass + '-add'); $$.parent().append(buttonRow); if (hideAddButton) buttonRow.hide(); - addButton = buttonRow.find('a'); + addButton = buttonRow.find('button'); } else { // Otherwise, insert it immediately after the last form: - $$.filter(':last').after('' + options.addText + ''); + $$.filter(':last').after(''); addButton = $$.filter(':last').next(); if (hideAddButton) addButton.hide(); } @@ -201,7 +201,7 @@ totalForms.val(formCount + 1); // Check if we're above the minimum allowed number of forms -> show all delete link(s) if (showDeleteLinks()){ - $('a.' + delCssSelector).each(function(){$(this).show();}); + $('button.' + delCssSelector).each(function(){$(this).show();}); } // Check if we've exceeded the maximum allowed number of forms: if (!showAddButton()) buttonRow.hide();