Editor node.js - Validate.numeric() renders default error message when error

Editor node.js - Validate.numeric() renders default error message when error

CapamaniaCapamania Posts: 238Questions: 83Answers: 5
edited December 4 in Editor

I have a node.js application, the .numeric() field validator seems to work, but it won't send a custom error message, instead I'm getting the default error message "Input not valid". Other validators and their custom error message seem to work fine, like the .notEmpty():

new Field( 'data.product_id' )
    .validator( Validate.notEmpty( new Validate.Options({ message: 'Invalid. Value must be set.' }) ) )
    .validator( Validate.numeric( new Validate.Options({ message: 'Invalid. Value must be numeric.' }) ) )

If I provide for instance "dddd" in the field, I'm getting error message .numeric():

Input not valid

If I provide nothing "", I'm getting error message .notEmpty():

Invalid. Value must be set.

How can I provide a custom error message for .numeric()?

Editor: "datatables.net-editor-server": "^2.1.2",
Node: v22.20.0

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 65,385Questions: 1Answers: 10,853 Site admin
    Answer ✓

    The signature for the numeric validator is actually:

    public static numeric(
      decimal: string = '.',
      cfg: ValidationOptions | null = null
    ): IValidator {
    

    You need to use:

    Validate.numeric(
      '.',
      new Validate.Options({
        message: 'Invalid. Value must be numeric.'
      })
    )
    

    The decimal place is missing in the documentation on the site - that's my mistake, apologies. I'll correct that!

    Allan

  • CapamaniaCapamania Posts: 238Questions: 83Answers: 5

    Great, thanks!

Sign In or Register to comment.