From 4cc1351bdd59dd94784ea952734ecb312d082de7 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 4 Oct 2018 23:37:52 -0700 Subject: [PATCH] More JS tweaks (WIP) --- resources/views/hardware/edit.blade.php | 47 ++++++++++++++++++------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/resources/views/hardware/edit.blade.php b/resources/views/hardware/edit.blade.php index 66b699ca08..f360002d49 100755 --- a/resources/views/hardware/edit.blade.php +++ b/resources/views/hardware/edit.blade.php @@ -203,36 +203,59 @@ // Add another asset tag + serial combination if the plus sign is clicked $(document).ready(function() { - var max_fields = 10; //maximum input boxes allowed + var max_fields = 3; //maximum input boxes allowed var wrapper = $(".input_fields_wrap"); //Fields wrapper var add_button = $(".add_field_button"); //Add button ID - var box_html = ''; + var x = 1; //initial text box count + var base_increment = $("#asset_tag").val(); + var incremented_tag = base_increment.replace(/[^\d]/g, ''); + + - var x = 1; //initial text box count $(add_button).click(function(e){ //on add input button click - e.preventDefault(); - if(x < max_fields){ //max input box allowed - x++; //text box increment - box_html += '
'; + e.preventDefault(); + var box_html = ''; + + // Check that we haven't exceeded the max number of asset fields + if (x < max_fields) { + x++; //text box increment + incremented_tag++; + console.log(x); + + box_html += ''; + box_html += '
'; box_html += '
'; - box_html += ''; - box_html += '
'; + box_html += ''; + box_html += '
'; + box_html += '
'; box_html += ''; box_html += '
'; box_html += '
'; box_html += '
'; - box_html += '
'; + box_html += '
'; box_html += '
'; box_html += ''; box_html += '
'; box_html += '
'; + box_html += ''; $(wrapper).append(box_html); + + // We have reached the maximum number of extra asset fields, so disable the button + } else { + $(".add_field_button").attr('disabled'); + $(".add_field_button").addClass('disabled'); } }); - $(wrapper).on("click",".remove_field", function(e){ //user click on remove text - e.preventDefault(); $(this).parent('div').parent('div').remove(); x--; + $(wrapper).on("click",".remove_field", function(e){ //user clicks on remove text + $(".add_field_button").removeAttr('disabled'); + $(".add_field_button").removeClass('disabled'); + e.preventDefault(); + console.log(x); + + $('.fields_wrapper').parent('div').remove(); + x--; }) });