$(".btn_submit_AddProgram_OptionSet").off("click");
var countuid = 0;
$(".btn_submit_AddProgram_OptionSet").on("click", function() {
var countBlank = 0;
$('.optValueProgram').each(function() { //iterate all listed class items
if (_.isEmpty($(this).val())) {
countBlank += 1;
}
});
var typeOfaTTR = $("#attrType").val();
if ($('#add_optNameProgram').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) {
// $("#TypeofOption").append("");
var optionsObj = {};
var arr = $('input[name="added_product_name[]"]').map(function() {
return this.value; // $(this).val()
}).get();
if (arr.length > 1) {
$("#TypeofOptionAttr").empty();
console.log(arr);
// var uniq = _.uniq(arr);
var tempobj = {};
var isDuplicateArr = false;
for (let i in arr) {
tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')];
if (tempobj[arr[i].toLowerCase()] > 1) {
isDuplicateArr = true;
break;
}
}
// console.log(uniq);
if (!isDuplicateArr) {
var optionName_Program = $("#add_optNameProgram").val();
// console.log("arrya");
// console.log(optionArray);
countuid++;
optionsObj.id = "optionvals" + countuid;
optionsObj.name = optionName_Program;
optionsObj.values = arr;
if (optionArray.length > 0) {
var duplicatecheck = isDuplicateReord(optionArray, optionsObj);
if (duplicatecheck) {
bootbox.alert({
size: "small",
title: "iMonitor +",
message: "Option Already Available with this name.",
callback: function() {
}
});
} else {
optionArray.push(optionsObj);
$("#addNewProgramDefineOptionSetModal").modal("hide");
}
} else {
optionArray.push(optionsObj);
$("#addNewProgramDefineOptionSetModal").modal("hide");
}
$("#TypeofOptionAttr").html('');
$.each(optionArray, function(i, e) {
$("#TypeofOptionAttr").append("");
})
// $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS
} else {
bootbox.alert({
size: "small",
title: "iMonitor +",
message: "Option Value Can't be Same.",
callback: function() {
}
});
}
} else {
bootbox.alert({
size: "small",
title: "iMonitor +",
message: "Please add minimum two option.",
callback: function() {
}
});
}
} else {
bootbox.alert({
size: "small",
title: "iMonitor +",
message: "Please Enter all required fields",
callback: function() {
}
});
}
})