Probable bug on Validate::numeric

Probable bug on Validate::numeric

nessinitsnessinits Posts: 86Questions: 27Answers: 0
            Field::inst( 'am_templates.title' )
                ->validator( Validate::numeric(ValidateOptions::inst() ->message('Numeric only') ) )

Leads to:

Catchable fatal error:  Object of class DataTables\Editor\ValidateOptions could not be converted to string in /datatables/php/lib/Editor/Validate.php on line 422

Is this a bug?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,431Questions: 1Answers: 10,048 Site admin

    The first parameter to be passed into the Validate::numeric() function should be the decimal place character, not a ValidateOptions instance - e.g.:

    Field::inst( 'am_templates.title' )
        ->validator( Validate::numeric('.', ValidateOptions::inst() ->message('Numeric only') ) )
    

    It looks like the PHP validation documentation misses that - sorry! I'll have it corrected forthwith.

    Allan

  • allanallan Posts: 61,431Questions: 1Answers: 10,048 Site admin
    Answer ✓

    Its fixed now.

    Regards,
    Allan

  • jukimv1986jukimv1986 Posts: 4Questions: 0Answers: 0
    edited November 2019

    I had to use

    Validate::minNum("0",**"."**,ValidateOptions::inst()->message("Formato no válido.")) 
    

    or it would throw the same error. I am using version 1.9.2

  • allanallan Posts: 61,431Questions: 1Answers: 10,048 Site admin

    That looks correct if you are using a minNum validator. The error above was for the numeric validator.

    Allan

  • jukimv1986jukimv1986 Posts: 4Questions: 0Answers: 0

    Thanks allan, though I was mentioning it because the current example at https://editor.datatables.net/manual/php/validation#Examples confused me.

This discussion has been closed.