$(document).on('page:beforein', '.page[data-name="product_add"]', async function (e) {

  console.log('app product_add ready')

  let sel_brand =``;

  for (let i in ar.brand) {

    sel_brand +=`<label class="radio" style="margin-left: 5px">

      <input type="radio" name="p5_brand" value="`+ar.brand[i]+`">

      <i class="icon-radio"></i>

    </label>`+ar.brand[i];

  }

  $$("#p5_brand").html(sel_brand);

});



$$(document).on('page:init', '.page[data-name="product_add"]', function(e) {

  $(document).off("click", "#product_add_button").on("click", "#product_add_button", function(e) {

    e.preventDefault();

    const name = $('#p5_name').val();

    const code = $('#p5_item_code').val();

    let brand = $('input[name="p5_brand"]:checked').val();

    const price_per_unit = $('#p5_price_per_unit').val();



    let req = {

      name,code,brand,price_per_unit

    }

    if (name && brand && price_per_unit && code) {

      product_add(req);

    } else {

      app.dialog.alert("All fields are required", "Product Add Errors");

    }

  });

})