function validateCatalog() {
  var id = "items";
  array[id].validation = [];
  var settings = validationSettings["interaction studio"]["catalog"];
  
  // Check _id field
  if(array[id].meta.fields.indexOf('_id')>-1){
    array[id].validation.push(settings.messages.fieldId[1]);
  } else {
    array[id].validation.push(settings.messages.fieldId[0]);
  }

  // Check name field
  if(array[id].meta.fields.indexOf('name')>-1){
    array[id].validation.push(settings.messages.fieldName[1]);
  } else {
    array[id].validation.push(settings.messages.fieldName[0]);
  }

  // Check itemType field
  if(array[id].meta.fields.indexOf('itemType')>-1){
    var catalogOptions = sort([...new Set(array[id].data.map(x => x.itemType))]);
    $.each(["a","b","p"], function( index, value ) {
      catalogOptions.erase(value);
    });
    var msg = (catalogOptions.length > 0) ? settings.messages.itemType[0] : settings.messages.itemType[1];
    array[id].validation.push(msg);
  } else {
    array[id].validation.push(settings.messages.fieldType[0]);
  }

  // Check category field
  if(array[id].meta.fields.indexOf('category')>-1){
    array[id].validation.push(settings.messages.fieldCategory[1]);
  } else {
    array[id].validation.push(settings.messages.fieldCategory[0]);
  }

  // Check price field
  var priceOptions = sort([...new Set(array[id].data.map(x => x.price))]);
  var priceOptions = priceOptions.filter(function(v){return v!==''});
  if((!isNaN(parseFloat(priceOptions[0])) && !isNaN(parseFloat(priceOptions[priceOptions.length-1])) && array[id].meta.fields.indexOf('price')>-1) || priceOptions.length ==0){
    array[id].validation.push(settings.messages.fieldPrice[1]);
  } else {
    array[id].validation.push(settings.messages.fieldPrice[0])
  }

  // Render results
  var resultsHeader = '<div class="slds-text-heading_medium slds-p-bottom_small">Validation Results</div>';
  $('#validation-results').html(resultsHeader + resultsList(array[id].validation));
  $('#validation-results').removeClass('slds-hide');

  // Check if user can proceed
  if($('.slds-theme_error').length > 0) {
    $('#upload').find('.slds-button_brand').prop('disabled', true);
   } else {
     $('#upload').find('.slds-button_brand').prop('disabled', false);
   }
}
// Function to validate each catalog type based on default settings
Function to validate each catalog type based on default settings
Function to validate each catalog type based on default settings
function validateCatalog() {
  var id = "items";
  array[id].validation = [];
  var settings = validationSettings["interaction studio"]["catalog"];
  if(array[id].meta.fields.indexOf('_id')>-1){
    array[id].validation.push(settings.messages.fieldId[1]);
  } else {
    array[id].validation.push(settings.messages.fieldId[0]);
  }
  if(array[id].meta.fields.indexOf('name')>-1){
    array[id].validation.push(settings.messages.fieldName[1]);
  } else {
    array[id].validation.push(settings.messages.fieldName[0]);
  }
  if(array[id].meta.fields.indexOf('itemType')>-1){
    var catalogOptions = sort([...new Set(array[id].data.map(x => x.itemType))]);
    $.each(["a","b","p"], function( index, value ) {
      catalogOptions.erase(value);
    });
    var msg = (catalogOptions.length > 0) ? settings.messages.itemType[0] : settings.messages.itemType[1];
    array[id].validation.push(msg);
  } else {
    array[id].validation.push(settings.messages.fieldType[0]);
  }
  if(array[id].meta.fields.indexOf('category')>-1){
    array[id].validation.push(settings.messages.fieldCategory[1]);
  } else {
    array[id].validation.push(settings.messages.fieldCategory[0]);
  }
  var priceOptions = sort([...new Set(array[id].data.map(x => x.price))]);
  var priceOptions = priceOptions.filter(function(v){return v!==''});
  if((!isNaN(parseFloat(priceOptions[0])) && !isNaN(parseFloat(priceOptions[priceOptions.length-1])) && array[id].meta.fields.indexOf('price')>-1) || priceOptions.length ==0){
    array[id].validation.push(settings.messages.fieldPrice[1]);
  } else {
    array[id].validation.push(settings.messages.fieldPrice[0])
  }
  var resultsHeader = '<div class="slds-text-heading_medium slds-p-bottom_small">Validation Results</div>';
  $('#validation-results').html(resultsHeader + resultsList(array[id].validation));
  $('#validation-results').removeClass('slds-hide');
  if($('.slds-theme_error').length > 0) {
    $('#upload').find('.slds-button_brand').prop('disabled', true);
   } else {
     $('#upload').find('.slds-button_brand').prop('disabled', false);
   }
}
function validateCatalog ( ) { var id = "items" ; array [ id ] . validation = [ ] ; var settings = validationSettings [ "interaction studio" ] [ "catalog" ] ; if ( array [ id ] . meta . fields . indexOf ( '_id' ) > - 1 ) { array [ id ] . validation . push ( settings . messages . fieldId [ 1 ] ) ; } else { array [ id ] . validation . push ( settings . messages . fieldId [ 0 ] ) ; } if ( array [ id ] . meta . fields . indexOf ( 'name' ) > - 1 ) { array [ id ] . validation . push ( settings . messages . fieldName [ 1 ] ) ; } else { array [ id ] . validation . push ( settings . messages . fieldName [ 0 ] ) ; } if ( array [ id ] . meta . fields . indexOf ( 'itemType' ) > - 1 ) { var catalogOptions = sort ( [ ... new Set ( array [ id ] . data . map ( x => x . itemType ) ) ] ) ; $ . each ( [ "a" , "b" , "p" ] , function ( index , value ) { catalogOptions . erase ( value ) ; } ) ; var msg = ( catalogOptions . length > 0 ) ? settings . messages . itemType [ 0 ] : settings . messages . itemType [ 1 ] ; array [ id ] . validation . push ( msg ) ; } else { array [ id ] . validation . push ( settings . messages . fieldType [ 0 ] ) ; } if ( array [ id ] . meta . fields . indexOf ( 'category' ) > - 1 ) { array [ id ] . validation . push ( settings . messages . fieldCategory [ 1 ] ) ; } else { array [ id ] . validation . push ( settings . messages . fieldCategory [ 0 ] ) ; } var priceOptions = sort ( [ ... new Set ( array [ id ] . data . map ( x => x . price ) ) ] ) ; var priceOptions = priceOptions . filter ( function ( v ) { return v !== '' } ) ; if ( ( ! isNaN ( parseFloat ( priceOptions [ 0 ] ) ) && ! isNaN ( parseFloat ( priceOptions [ priceOptions . length - 1 ] ) ) && array [ id ] . meta . fields . indexOf ( 'price' ) > - 1 ) || priceOptions . length == 0 ) { array [ id ] . validation . push ( settings . messages . fieldPrice [ 1 ] ) ; } else { array [ id ] . validation . push ( settings . messages . fieldPrice [ 0 ] ) } var resultsHeader = '<div class="slds-text-heading_medium slds-p-bottom_small">Validation Results</div>' ; $ ( '#validation-results' ) . html ( resultsHeader + resultsList ( array [ id ] . validation ) ) ; $ ( '#validation-results' ) . removeClass ( 'slds-hide' ) ; if ( $ ( '.slds-theme_error' ) . length > 0 ) { $ ( '#upload' ) . find ( '.slds-button_brand' ) . prop ( 'disabled' , true ) ; } else { $ ( '#upload' ) . find ( '.slds-button_brand' ) . prop ( 'disabled' , false ) ; } }
Function to validate each catalog type based on default settings
Function to validate each catalog type based on default settings
// Check _id field // Check name field // Check itemType field // Check category field // Check price field // Render results // Check if user can proceed