From 3e77534dcfad4bd12f5c8d69c22363213225ff9e Mon Sep 17 00:00:00 2001 From: Matt-Yorkley Date: Fri, 25 Nov 2016 01:31:45 +0000 Subject: [PATCH] Product variant form script --- .../_form/on_demand_script.html.haml.deface | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 app/overrides/spree/admin/variants/_form/on_demand_script.html.haml.deface diff --git a/app/overrides/spree/admin/variants/_form/on_demand_script.html.haml.deface b/app/overrides/spree/admin/variants/_form/on_demand_script.html.haml.deface new file mode 100644 index 0000000000..6bd45a0d49 --- /dev/null +++ b/app/overrides/spree/admin/variants/_form/on_demand_script.html.haml.deface @@ -0,0 +1,28 @@ +/ insert_bottom "[data-hook='admin_variant_form_fields']" +:javascript + + $(document).ready(function() { + + var on_demand = $('input#variant_on_demand'); + var on_hand = $('input#variant_on_hand'); + + on_hand.attr('disabled', on_demand.attr('checked')); + + on_demand.change(function(){ + + on_hand.attr('disabled', this.checked); + + if(this.checked) { + on_hand.attr('data-stock', on_hand.val()); + on_hand.val("Infinity"); + } else { + if(on_hand.attr('data-stock') !== undefined) { + on_hand.val(on_hand.attr('data-stock')); + } else { + on_hand.val("0"); + } + } + + }); + + });