ValidateOptions not working with values Validator

ValidateOptions not working with values Validator

dwmullinsdwmullins Posts: 2Questions: 1Answers: 0

Not getting any of the ValidateOptions to work with the values Validator.

Here is the snippet in question:

        Field::inst( 'branch' )
            ->validator( Validate::values( array('FAQ', 'FAM', 'FOK', 'FLR', 'FEL', 'FHS', 'FSA', 'FDF') ), ValidateOptions::inst()
                ->allowEmpty( false )
                ->optional( false )
                ->message( 'A Division ID is required' ) 
             ),

Any ideas/suggestions greatly appreciated.

Thanks,

Don

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Those are two validations, so I believe they need to be split like this:

    Field::inst( 'branch' )
        ->validator( Validate::values( array('FAQ', 'FAM', 'FOK', 'FLR', 'FEL', 'FHS', 'FSA', 'FDF') ))
        ->validator( Validate::notEmpty( ValidateOptions::inst()
            ->message( 'A Division ID is required' ) 
         ) ),
    

    Hope that does the trick,

    Colin

  • dwmullinsdwmullins Posts: 2Questions: 1Answers: 0

    Thanks that worked perfectly

Sign In or Register to comment.