From 04417c2b730872a45a2f8c87030109dbaf5be2c4 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Tue, 4 Nov 2008 10:21:47 -0600 Subject: [PATCH] Fix for Bug 2700, Keeping Data When Adding Multiple Items When cloning the set of inputs, the new js increments the IDs of each form field (to keep them unique) and automatically selects the option that was selected in the cloned group. Signed-off-by: Galen Charlton --- koha-tmpl/intranet-tmpl/prog/en/js/additem.js | 26 ++++++++++++++++++- .../prog/en/modules/acqui/orderreceive.tmpl | 24 ++++++++--------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/additem.js b/koha-tmpl/intranet-tmpl/prog/en/js/additem.js index a1e3092579..a9eeda9e59 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/additem.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/additem.js @@ -16,7 +16,31 @@ function check_additem() { } $(document).ready(function(){ $(".cloneItemBlock").click(function(){ - $(this).parent().parent().clone(true).insertAfter($(this).parent().parent()).find("a.deleteItemBlock").show(); + var clonedRow = $(this).parent().parent().clone(true); + clonedRow.insertAfter($(this).parent().parent()).find("a.deleteItemBlock").show(); + // find ID of cloned row so we can increment it for the clone + var count = $("input[id^=volinf]",clonedRow).attr("id"); + var current = Number(count.replace("volinf","")); + var increment = current + 1; + // loop over inputs + var inputs = ["volinf","barcode"]; + jQuery.each(inputs,function() { + // increment IDs of labels and inputs in the clone + $("label[for="+this+current+"]",clonedRow).attr("for",this+increment); + $("input[name="+this+"]",clonedRow).attr("id",this+increment); + }); + // loop over selects + var selects = ["homebranch","location","itemtype","ccode"]; + jQuery.each(selects,function() { + // increment IDs of labels and selects in the clone + $("label[for="+this+current+"]",clonedRow).attr("for",this+increment); + $("input[name="+this+"]",clonedRow).attr("id",this+increment); + $("select[name="+this+"]",clonedRow).attr("id",this+increment); + // find the selected option and select it in the clone + var selectedVal = $("select#"+this+current).find("option:selected").attr("value"); + $("select[name="+this+"] option[value="+selectedVal+"]",clonedRow).attr("selected","selected"); + }); + var quantityrec = parseFloat($("#quantityrec").attr("value")); quantityrec++; $("#quantityrec").attr("value",quantityrec); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tmpl index 88522b411d..50d1d2669c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tmpl @@ -46,12 +46,12 @@ fieldset.rows .itemblock fieldset.action { padding:.5em; }
    -
  1. -
  2. -
  3. - " />
  4. -
  5. -
  6. +
  7. + " />
  8. +
  9. +
  10. -
  11. - @@ -69,8 +69,8 @@ fieldset.rows .itemblock fieldset.action { padding:.5em; }
  12. -
  13. - @@ -79,8 +79,8 @@ fieldset.rows .itemblock fieldset.action { padding:.5em; }
  14. -
  15. - -- 2.39.5