Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81728

Node.js datatables editor - Custom/Unique validation for multiple columns

$
0
0

The Validator.dbUnique() let's me validate a value prior to insert if the value is unique in that column. Ref. https://editor.datatables.net/manual/nodejs/validation

new Field( 'groups.name' )
new Field( 'groups.product_id' ),
    .validator( Validator.dbUnique() )
new Field( 'groups.type' )
new Field( 'groups.status' );       

What I need though is a validation for multiple columns. So insert the new record only if the product_id IS NOT of type=1 and status=2 found.

Here is a php example combining multiple columns https://datatables.net/forums/discussion/57729/unique-validation-for-multiple-columns

->validator( function($editor, $action, $data){
    if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT){
        foreach ($data['data'] as $pkey => $values ){
            $count = $editor->db()->query('select')->get('*')->table('teachers_subjects')
                ->where('teachers_subjects.teacher', $values['teachers_subjects']['teacher'])
                ->where('teachers_subjects.subject', $values['teachers_subjects']['subject'])
                ->exec()
                ->count();                      
            if ($count == 1){
                return 'This selection is already in the database.';
            }
        }
    }
})

But how to do so with node.js ?

Rf. https://editor.datatables.net/manual/nodejs/validation#Global-validators


Viewing all articles
Browse latest Browse all 81728

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>