Created
August 23, 2018 17:11
-
-
Save faizaankhan/f5a0e133831c478d89d08049551cecfb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).on('turbolinks:load', function() { | |
console.log("may i come") | |
if ( $(".quantity").length > 0 ) { | |
updateQuantity(); | |
}; | |
}); | |
updateQuantity = () => { | |
$(".quantity").bind('keyup change click mouseup', function() { | |
const quantity = $(".quantity").val(); | |
console.log($(this).data("previousValue")) | |
if (! $(this).data("previousValue") || $(this).data("previousValue") != $(this).val()) { | |
$.ajax({ | |
url: "/update_quantity", | |
beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))}, | |
type: "POST", | |
data: {id: $(this).attr('data-order_item-id'), quantity: quantity} | |
}) | |
$(this).data("previousValue", $(this).val()); | |
} | |
}); | |
$(".quantity").each(function () { | |
$(this).data("previousValue", $(this).val()); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment