When data in a cell has been change, can I trigger validation of an other related cell?

Pardon my non-technical language. I’m not very familiar with technical terms.

I have 2 cells which are related to each other.
I wanna make sure that either one is not empty when the other one is not empty.
I had validated both of them based on data within each other.

But when I select both of them and delete their data at the same time, they can’t pass the validation and are marked red.

So I had to make my page render or validate the whole table after editing any one of the cells so it would appear to be normal.

But the table becomes extremely slow. Did I miss something? Is there a better way to do this?

Hi @panjf1990

Can you share a demo that illustrates the current point you’re in with the code? I’d be the best way to check what happens.

@aleksandra_budnik Thanks for your timely reply.

Here is the demo.

Thank you.

Just to confirm:

  1. When we delete content from A1 the A2 should be marked invalid
  2. When we delete content from A2 the A1 should be marked invalid
  3. If both cells are empty they are both valid

Actually,

  1. when we delete content from A1, if B1 is not empty then A1 should be marked invalid;
  2. when we delete content from B1, if A1 is not empty then B1 should be marked invalid;
  3. If both cells are empty they are both valid

Consider this an inventory sheet. The business logic would be something like this:
Column A contains amount, while column B contains SKU.
There is no point having “amount” without specifying the product you are referring to, vise versa.

What I would love to achieve is when I delete content in A1 and B1 at the same time, they should be valid. But now they are both marked as invalid.

It would be hard to achieve with a validator but it might be possible via afterChange hook. The only flaw is that we won;t be able to use the predefined htInvalid class and we’d need to create a custom one.
The afterChange hook provides a full list of changes for all the cells so even if two cells are changed in the same time we have a control over what is going on.

The afterChange provides an array of changes. If the array is length > 1 then user made at least 2 changes (two+ cells were changed).

I’d love to create the logic for this hook for you but it exceeds my abilities as a part of the forum basic support. However, I can help if you’ll decide to build it by yourself.

1 Like

Thanks for your help. We have switched to afterchange as you suggested.
It’s not perfect but good enough.
:slight_smile:

I’m happy that I could help.

I think that we can close this topic.