Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.     function loadAttributes() {
  3.         $.ajax({
  4.             url: $("#siteUrl").val(),
  5.             method: 'post',
  6.             dataType: 'json',
  7.             data: {
  8.                 categoryId: $('#categoryId').val()
  9.             }
  10.         })
  11.             .done(function(res) {
  12.                 $("#detailsList").html('');
  13.                 $(res).each(function() {
  14.                     var html='<div class="form-group">' +
  15.                         '<input type="hidden" name="detailIds[]" value="'+this.id+'">' +
  16.                         '<label for="">'+this.name+'</label>' +
  17.                         '<input type="text" name="details[]" class="form-control" placeholder="'+this.name+'" required>' +
  18.                         '</div>';
  19.                     $("#detailsList").append(html);
  20.                 })
  21.             })
  22.     }
  23.     loadAttributes();
  24.     $('#categoryId').on('change', function(e) {
  25.         loadAttributes();
  26.     });
  27.     $('#plus').on('click', function(e) {
  28.         e.preventDefault();
  29.         var html='<div class="form-group">' +
  30.             '<label for="">Image</label>' +
  31.             '<div class="row">' +
  32.             '<div class="col-10 col-md-11">' +
  33.             '<input type="file" name="images[]" class="form-control">' +
  34.             '</div>' +
  35.             '<div class="col-2 col-md-1 text-right">' +
  36.             '<button type="button" class="btn btn-outline-danger delete">X</button>' +
  37.             '</div>' +
  38.             '</div>' +
  39.             '</div>';
  40.         $("#imagesList").append(html);
  41.         $(".delete").on('click', function() {
  42.             $(this).parent().parent().parent().remove();
  43.         });
  44.     });
  45. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement