Custom validation error on inline edit of different field

Custom validation error on inline edit of different field

phpkidphpkid Posts: 10Questions: 2Answers: 0
edited October 2016 in Free community support

Hi,

I'm using Datatables Editor version 1.5.6 and have implemented inline editing.

However the following validation breaks and the 'Journal date cannot be before 1st January 2009' error is returned when a different field is edited inline:

->validator(function($journaldate, $data, $opts) {
    $formattedDate = str_replace('/', '-', $journaldate);
    if ( strtotime($formattedDate) < strtotime('2009-01-01') )
        return 'Journal date cannot be before 1st January 2009';
    else if (strtotime($formattedDate) > strtotime('+12 months'))
        return 'Journal date cannot be more than a year in the future';
    return true;
    } )

This error can be avoided by adding:

submit: 'allIfChanged'

to the inline edit initialisation but out of stubbornness, and curiosity of why it this is occurring, I want to stop validation happening when the related field isn't submitted.

EDIT: The same issue is happening when the minMaxNum validator is used. Here is the validator code:

->validator( 'Validate::minMaxNum', array(
     'min'       => 1,
     'max'       => 1000000,
    'message'   => 'Please enter a number greater than 0 and less than 1 million'
) )

Any help is appreciated.

Thanks,
Alec

This discussion has been closed.