Case when target.item of a repeater is empty


#1

Case if target.item in a repeater is empty

Hi,

In the attached example, when I type a number in the slot (1,2,3) and I click on the button, then the bottom table gets the data for the slot I typed.

For example, when I type 1 in the first row and click the button then the data “abc” and “2” are transferred into the row 1 of the bottom table. If I type 2 the same data will be transferred to the row 2.

My problem is that, in case the bottom table/row has already data in it, I should fire a message to the user warning that there are already data in that row/slot and the user can chose either to abort the operation of to overwrite the previous data with the current one.

In a repeater, I’m not able to check if the target item of the repeater contains data, that’s why I’m asking for your help. Thank you in advance.example2.rp (119.1 KB)


#2

This is a good example of the “How do I get data from a specific repeater row?” problem. …With an interesting twist of then updating that repeater row if that data is null. The classic way to handle this problem is with the “listener method” (well documented on this forum). You “ping” a widget in the repeater which “listens” to this ping and reports back if it is the correct row. It works like this:

  1. Set a “target flag” to define which row you want.
    a. This can be a global variable or the text value of any widget.
    b. For example, if you want row 3 you could set OnLoadVariable to “3”. (But in your prototype you’ve already set the “selectedslot” variable to a number, so this is already done.)

  2. Trigger an otherwise unused event of a widget in the repeater. This is the “ping.”
    a. Moved or Rotated are commonly used for this.
    b. This must be done outside the repeater so it will be triggered for each and every row.
    c. For example, if you have an interaction of “Move ++NumSlot by (0, 0)” then the widget named ++NumSlot will be “moved” (by zero pixels, so no actual movement) meaning its Moved event will be called for the ++NumSlot widget in every row.

  3. Add a case to this “trigger event” to test a value in this row against the target flag. This is how the row “listens for the ping.”
    a. If it is a “target row”, return the data from this row (or whatever actions you need) typically by setting the value of global variables or text values for widgets.
    b. All other “non-target” rows will fail this test, so they will essentially ignore the ping.
    c. For example, ++NumSlot would have a Moved event with case logic like, “If [[Item.numslot]] equals selectedslot and my columns are not empty, show the warning message, else if empty, update this row.”

So, in your InputTable repeater, the button first needs to ping the row matching ++inputSlot, by moving the corresponding ++NumSlot widget in the AllocTable repeater. Then, ++NumSlot needs to test if it is the requested slot and if the ““handler”” or "“colli” columns already have data, show the warning message, otherwise if it is the requested slot, trigger the row update. Since you have already stored the necessary data in global variables, ++NumSlot could directly update its own row. However, you’ve created another possibility that needs to be handled: If the row is non-empty it shows the warning message and the warning message has a “Yes” button to confirm the row should be updated.

I thought it would be interesting to try a kind of “double listener method” to solve this. The BUTTON widget in InputTable pings ++NumSlot in AllocTable, then if ready for an update, ++NumSlot pings BUTTON to signal it can update this row. Likewise, the “Yes” button in the warning message can ping BUTTON (by moving it) to force the update.

Here is an updated file:
example2.rp (150.1 KB)

  • BUTTON has a Click or Tap event with one action: Fire Event ++NumSlot fire Moved
    I prefer this to Move ++NumSlot by (0, 0) because it makes it more obvious that it is a special thing and ++NumSlot will not actually be moved anywhere.
  • BUTTON also has a Moved event that updates AllocTable (if it is the same button in the same row that was originally clicked.)
  • ++NumSlot has a Moved event with two cases.
    • To test if it is the correct row and its data columns are not empty, I had to use some fairly tricky logic:
      If [[Item.NumSlot]] equals value of selectedslot and
      [[Item.handler == '' && Item.colli == '']] equals false
      Show warning message
    • The second case fires the Move event of BUTTON to ping it back and update the row.

#3

This is absolutely great mbc66!!! :grinning:
Your solutions worked really well and I could learn a lot from your explanation!
Thank you so much!