Compare rows

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

azaleas
Ebase User
Posts: 81
Joined: Thu Jul 30, 2015 12:44 pm

Compare rows

#1

Postby azaleas » Tue Sep 01, 2015 12:13 pm

I have a table and add row button to add two columns. Once Add row is clicked I want to check the value of the row with the DB, to avoid Duplicate entries. I think about copying the table and iterate for the matches, but it seems clumsy and messy. Is there another way I can use?
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Tue Sep 01, 2015 3:23 pm

From what you say I'm not too sure what your user interface is. Do you want the user to have the ability to add as many rows as they like than validate at the end? Or do you want to check each new row as the data is entered?

If you want to validate each row as the user enters it, you might find it easier to add a + icon at the top of the table or an additional button at the end of the table, instead of using the provided Add Row functionality. Then you could have two additional fields (not part of the table) at the bottom of the table for the new row data plus an additional "Add" button. So the user would click the + icon, type in the two new fields then click the Add button. At this point you check the existing table data for duplicates - if it's OK you add a row to the table with insertRow() then copy the values to the new row. In this way you are separating existing table data from new data until it has been validated. You could dynamically hide/show these new row fields as required. You could also set your table to display only if this makes sense.
0 x

azaleas
Ebase User
Posts: 81
Joined: Thu Jul 30, 2015 12:44 pm

#3

Postby azaleas » Sun Sep 06, 2015 1:38 pm

Yes, I want to check on each row. I think about putting a Immediate validation to a field, then check the value from the table, if it exists, then a warning message pops up.

How it can be achieved with using built in Add Row function? I just want it to keep as simple as possible for the client. Just one button, Add Row, that's it.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#4

Postby Jon » Mon Sep 07, 2015 8:31 am

There might be a bit of confusion here: checking user input and the Add Row button are separate things. The Add Row button will add a new empty row to the table - you have an option to add an event to this which then allows you to supply values (programatically) for the new row.

The user can then enter some values in the new row, or any other row if it's not display only. Your suggestion to check the value with Immediate Validation is fine, but bear in mind that this fires when the user leaves the field e.g. via tab or clicking something else. If you want to check the value doesn't already exist, you would use something like this in an Immediate Validation event (assumes the ID column is unique);

Code: Select all

var tab = tables.MYTABLE;
var enteredId = tab.ID.value;       // get id just entered
if (enteredId )                       // ignore if no value
{
   var enteredRow = tab.currentRow;    // get current row
   var rows = tab.getRows();           
   while (rows.next())
   {
      if ( enteredRow != tab.currentRow)
      {
         if (enteredId == tab.ID.value)
         {
            event.owner.addErrorMessage("Duplicate");
         }
      }
   }
}
0 x


Who is online

Users browsing this forum: No registered users and 14 guests