How to avoid error "Please enter a valid data type ..." when leaving the field blank

phpGrid automatically sets the validation rules to check for data types that match with the DB field type. This works for the most part except when the value is NULL since NULL is not a value. One will get

"Field Name: please enter a valid ..."

In this case, custom data validation comes to the rescue 

Basically, you want to return 'true' when the value is integer AND null, which will subsequently become SQL NULL when saved. 

Pseudo code

[javascript]
function price_validation1(value, colname) {
    if(value === null || Number.isInteger(value)){
      return [true, ""]
    }
   return [false,colname + " must be null a positive integer."];
}

[php]
$dg->set_col_customrule('buyPrice', 'price_validation1');


Best,
Richard

Feedback and Knowledge Base