Concept for dataTable validator

I'm trying to figure out a way to make a validator for fields within a data table, because currently users are able to fill out one single field on a dataTable, then move on - regardless of whether the other dataTable fields are set as required.
There's an old thread here that it's been logged as a defect: https://community.plumsail.com/t/data-table-validators/7530

The concept I was playing with to make the validation for the field work:

  1. Create an integer field (outside of the dataTable)
  2. OnChange for the data table, set the integer field equal to a count of the values within the dataTable column
  3. Create a validator that compares to number of rows in the data table with the integer string field, and prevent save/send error if they are not equal

My problem is that I have no clue how the Javascript would work for that... any coders out there able to help?

Thanks!

Dear @Gabegia,
Thank you for bringing the issue to our attention! We'll make sure to fix it as fast as possible, it already has been quite a long wait.

For now, you can try a validator like this, where you can check values for different columns:

fd.control('DataTable1').addValidator({
    name: 'DataTable validator',
    error: "Fill out all required columns",
    validate: function(value){
  for(var i = 0; i < value.length; i++){
    if(!value[i].Column2 || !value[i].Column3){
      return false;
    }
  }
  return true;
}});
1 Like

Thanks @Nikita_Kurguzov! That worked perfect!

Gabe

Dear @Nikita_Kurguzov,

I have similar issue before and I'm trying to replicate the code on my Table, but now the form always showing the error even there's data on it. Here's my code. Could you help to check?

fd.rendered(function(){
    fd.control('TableContainer').validators.push({
        name: 'TableContainer validator',
        error: 'You at least need to input 1 Container Number',
        validate: function(value) {
            if (value.length == 0) {
                return false;
            }

            return true;
        }
    });
    
    fd.control('TableContainer').addValidator({
    name: 'TableContainer validator',
    error: "You can't submit with blank field.",
    validate: function(value){
    for(var i = 0; i < value.length; i++){
    if(!value[i].Column2 || !value[i].Column3){
      return false;
    }
  }
  return true;
}});
});

Dear @AdityaGiriHertanto,
Welcome back! How many columns do you have? Have you changed any column's name? What are the Names of the columns and what are their types?

Can you post a screenshot of a form with an error here?

Dear @Nikita_Kurguzov,

Thanks for your insight, just realized the column name wasn't changed and now it's worked perfectly. :smiley:

1 Like