Guest User

Untitled

a guest
Oct 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. <div class="col-sm-1">
  2. <button type="button" id="delete-transact" class="btn btn-default" data-toggle="tooltip" title="Delete All Entries" data-placement="right">
  3. <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
  4. </button>
  5. </div>
  6. <!-- Input field for search suggestion -->
  7. <form method="POST" action="{{URL::to('/search/transaction')}}" id="transAction">
  8. {{ csrf_field() }}
  9. <div class="col-sm-12">
  10. <div class="form-group">
  11. <input type="text" name="searchItem" id="transProductSearch" class="form-control" value="" title=""
  12. placeholder="Search product">
  13. <!--Container for dynamically created class "suggestion-box"-->
  14. <div id="suggestion-container"></div>
  15. </div>
  16.  
  17. </div>
  18. </form>
  19. <div class="cover">
  20. <div class="table-responsive">
  21. <form action="" method="">
  22. <table class="table table-hover">
  23. <thead>
  24. <tr>
  25. <th>Product</th>
  26. <th>Quantity purchased</th>
  27. <th>Quantity Available</th>
  28. <th>Price</th>
  29. </tr>
  30. </thead>
  31. <!--Container for dynamically created class "transaction entry"-->
  32. <tbody id="transaction-body">
  33.  
  34. </tbody>
  35. <tfoot>
  36. <tr class="tfoot">
  37. <td>Total</td>
  38. <td class="transactionTotal"></td>
  39. <td></td>
  40. <td></td>
  41. </tr>
  42. </tfoot>
  43. </table>
  44. </form>
  45. </div>
  46. </div>
  47.  
  48. $('#transProductSearch').on('keyup',function (e) { //Event listener for ajax request
  49. e.preventDefault();
  50. if($(this).val() !== ""){
  51. $.ajax({
  52. type: "POST",
  53. url: $('#transAction').attr('action'),
  54. data: $('#transAction').serialize(),
  55. success: function (response) {
  56. $(".suggestion-box").remove();//Removing every dynamically created "suggestion-box" class on every successful AJAX request;
  57. pEntities = [];
  58. response = jQuery.parseJSON(response);
  59. $.each(response, function (indexInArray, value) {
  60. $("#suggestion-container").append($('<div>',{class:"suggestion-box", text:value.productName}));
  61. pEntities[indexInArray] = {prodQuantity:"",prodId:"",prodPrice:"",prodName:""};
  62. pEntities[indexInArray].prodQuantity = value.quantity;
  63. pEntities[indexInArray].prodId = value.id;
  64. pEntities[indexInArray].prodPrice = value.price;
  65. pEntities[indexInArray].prodName = value.productName;
  66. });
  67. },
  68. error: function () {
  69. console.log($('#transAction').val());
  70. }
  71. });
  72. }
  73. else{
  74. $('.suggestion-box').remove()//Removing every suggestion box if input field is empty
  75. }
  76. });
  77.  
  78. $('#suggestion-container').on("click",'.suggestion-box', function (e) { // Event delegation to append new "transaction-entry" class
  79. var index = $(this).index();
  80. $('#transaction-body').append('<tr class="transaction-entry"><input hidden class="prodId" value="'+pEntities[index].id+'"/><td>'+pEntities[index].prodName+'</td><td><input class="quantityInput" style="color:black" type="number"></td><td>'+pEntities[index].prodQuantity +'</td><td class="productPrice">'+pEntities[index].prodPrice +'</td></tr>');
  81. $('.suggestion-box').remove();
  82. })
  83.  
  84. $('#delete-transact').click(function (e) {//Event listener to remove all transaction entry classes
  85. e.preventDefault();
  86. $('#transaction-body').empty();
  87. })
  88. $('#transaction-body').on("keyup",'.quantityInput',function (e) {//Event Delegation to output quantityInput value and index
  89. console.log($(this).val()+" "+$(this).index());
  90. });
Add Comment
Please, Sign In to add comment