trigger an event when any field in the block is change

I have a block with many widgets which will display a specific data from DB and then the user can change them (all fields are editable). I have created an event with an input structure to pass the new values entered by the user to the screen (Parent of block) and select this event in the OnChange event for each field(widget) and it is working fine.

Is there another way to do it once not for each field in the block.

Thanks in advance


Is the best way you have to do it if in fact you have to send everything to the parent.

Hi Sultan Alnaabi,

It depends on how your block/screens are structured, but I usually send to the screen level only a set of events regarding the action the user took, for example, Saved/Cancelled, to do redirections or give feedback to the user. 

If you really need all the data on the screen level (why?!), I believe your approach is the right way to do it. 

I think the best way to handle it (since you're already using a block) is to do the save logic directly from within the block where the fields are.

Then, you can just reload the data from the parent after the save function is called from within the block. 

This way you don't have to pass information back to the parent. The parent will just refresh the data that lives in the block and the "on parameters changed" should refresh the block itself. 

If all the data is contained in the block you don't even need to refresh the parent. 

I usually have a handler that send the full entry structure. It may have too much detail, but a single update action is the minimum visual content and for most structures it is not heavy.

As a rule of thumb:

-When the block receives an Id, the block does the retrieve and save. It is independent from the parent.

When the block receives a structure, the block returns the changed structure to the parent for parent to save. Because if you haven't sent the Id, it means you may not have the info on DB, so you do not want to save to database and will simply update the variable on screen.

Sometimes we have a mix of these. You can:

-send the id to the block, but send changes to parent to save all at once. As in adding product to cart but save a shopping list.

-send a structure to the block but save one by one (for instance , if you are validating entries one by one).

-or the worst case, you use some type of action id in the block and save to auxiliary entities with the pair session/action, but only at the end decide if they are to save or not. Useful when data is big and you cant send back and forth in handlers, like uploading documents.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.