Global validator

Global validator

jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

I'm attempting to create a global validator, like so:

    let editor = new Editor( db, 'external' )
        .validator( (editor, action, data) => {
            console.log(data);
            /*Object.keys( data.data ).forEach( function (key) {
                var values = data.data[key];
                console.log('key',key,'value',values);
            });*/
            return true;
        } )
        .fields(

From reviewing 'data', it looks like it only contains column data and not data as submitted by the client. After reviewing https://editor.datatables.net/manual/server, and https://editor.datatables.net/manual/nodejs/validation#Global-validators, it seems that it should contain a data object, but does not.

Am I missing something obvious?

This question has an accepted answers - jump to answer

Answers

  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

    A silly follow-up, while there doesn't appear to be a data definition at this level in the editor, it does exist for the field validator. If you need to do a global validator that takes submitted data into consideration, in NodeJS, req.body still contains all the submitted data.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    I would indeed expect the third parameter given to validator to contain the submitted data for the row. This is the code for it.

    I've just tried modifying my demo to add:

        editor.validator((e, action, data) => {
            console.log(action, data);
            return true;
        });
    

    And it outputs what is expected:

    edit {
      data: {
        row_58: {
          first_name: 'Airi',
          last_name: 'Satou',
          position: 'Accountant',
          office: 'Tokyo',
          extn: '',
          start_date: '2008-11-28',
          salary: '162700'
        }
      },
      action: 'edit'
    }
    

    What version of Editor's Node JS libraries are you using?

    Allan

  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

    User issue, you are absolutely correct.

    Upon refresh, it looks like the validator is called on a select, which causes a different dump of data that I didn't look at close enough. This is probably where it's important to look at action!

Sign In or Register to comment.