Validation Checks in Tables

This sample runs validation checks for values inside tables, when saving the record.
In this particular sample, the radio buttons determine the validation for the number fields.

Sample Image


Sample Code

// Validation check for odd and even numbers in tables

(function() {
    'use strict';

    var TABLE = 'checking_table'; // field code of the table of where the error checks will occur
    var NUMBER = 'mynumber'; // field code of a number field in the table 
    var NUMBERTYPE = 'radio_button'; // field code of a radio button field in the table
    var events = ['app.record.create.submit', 'app.record.edit.submit'];, function(event) {
        var record = event.record;
        var table = record[TABLE].value;

        for (var i in table) {
            if (!table.hasOwnProperty(i)) { continue; }
            var row = table[i].value;
            var num = row[NUMBER].value;
            var numType = row[NUMBERTYPE].value;
            var isEvenNumber = num % 2 === 0 ? true : false;

            if ((isEvenNumber && numType === 'Odd number') || (!isEvenNumber && numType === 'Even number')) {
                row[NUMBERTYPE].error = 'Type does not match';
            } else if (!num) {
                row[NUMBER].error = 'Insert a number';
        return event;


Make sure to match the Field code of your fields, with the Field code written in the code.
Note that tables themselves also have Field codes.


Refer to the Tutorial page, on how to add scripts to your app.

Was this article helpful?
1 out of 1 found this helpful
  • Avatar

    Let me make sure I understand:
    The for loop iterates over row "i" in "table" (where "table" is an array of objects). Since we're doing a "" loop over an array, we include the "if (!table.hasOwnProperty(i)) { continue; }" line to skip any of the array's inherited properties from up the prototype chain?

Please sign in to leave a comment.