Author Topic: Inline Editing: Prevent regex validation when cell is empty  (Read 2457 times)

Syreta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 19
    • View Profile
Inline Editing: Prevent regex validation when cell is empty
« on: March 20, 2019, 02:10:00 pm »
Hello,

I'm using a regex validation for a date field when editing a cell with date value. Is it possible to prevent the validation when the value of the cell is empty?

Thanks,
Syreta

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Inline Editing: Prevent regex validation when cell is empty
« Reply #1 on: March 20, 2019, 09:04:14 pm »
Callback function can be used in that case.

Code: [Select]
validations: [                   
{
type: function(ui){
var val = ui.value;
                                                        // if empty or correct date format.
if( !val || /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/.test(val) ){
   return true;
}
ui.msg = 'Not in mm/dd/yyyy format';
return false;
}
}
                ]

Syreta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Inline Editing: Prevent regex validation when cell is empty
« Reply #2 on: March 21, 2019, 11:33:41 am »
Ah... I didn't notice that a callback function can be used for validation type.

Many thanks!  :D