Hi All,
I have multiple tabs on main screen and on each tab selection showing different blocks .
The data filled in each block to be submitted from parent screen only.There is only one save button on parent screen for all of the blocks.
Can anyone suggest how to pass the data without any submit button from block to parent,
Regards
Hi @Preeti zade ,
Analyzing your question, it sounds like you are describing a pattern that uses the "Data Bag" concept. Although this approach is mostly outdated now and rarely recommended for new developments, it is still very common in legacy systems, and some clients still insist on keeping it.
To help you visualize this, I am sharing an exercise below that I usually give to my students to teach the Data Bag concept.
The Data Bag Concept
A Data Bag allows a main page (or parent block) with multiple child blocks to centralize all its information.
Based on your description, it looks like each tab in your application has its own block managing a piece of this bag.
Hello Rui,
I have similar case and similar common structure for all blocks.
Just to clarify,So one common structure for all the child blocks then on parent screen the local variable attached to common structure to be serialzed and sent on save on click on parent ? as we do not have the individual submits for each block.
Also,which approach will be better ,Having save on each block to pass the variables to parent and save from parent?As in future more blocks will be added so one structure parsing will take time and performance issues?
So, we have our general structure in the parent block, which acts as our single source of truth holding the data. Then, we have an input parameter in the child block—it doesn't need everything, just the specific fields the child needs. The child block triggers an event on every change, using an input parameter to send its current data state back to the parent. When you want to save to the database, you just call the save action from the parent block.
Note: If you don't want to constantly send data to the parent on every single change, you can implement logic to do this only when needed.
A technique I usually use is having the parent block control which tab or child block is active. When switching to another tab, the data from the previously open block is automatically updated in the parent
Hi Preeti,
The best way is to use Events to communicate with the parent. However, you should always take care of how to manage your strucrure.Example if your page has the below structure
You should hold the top structure at screen level. Each web block should have its own input structue relevant to the web block. So, for the address web block tab, the web block should have only the below input structure
and personal details tab's web block should have the below structure.
All web blocks should have an Event OnDataChanged (Example AddressDetails web block has Address strucuture and OnDataChanged with same address structure as input param.
Now, whenever you change data on any field, it generally calls an OnChange. Inside onChange call the Event OnDataChanged with updated data.
This directly calls the OnDataChanged Handler on the parent screen and the parent screen then can update the Original user structure asUser.AddressDetails = UpdatedAddress
Same implementation goes for all the web blocks. and allows you to update all the sections of the original user structure. Later you can save the full structure from the screen.
I have displayed the implementation for a Form, but this can be implemented for any table, list or complex strcuture.
IMPORTANT NOTE: You would need a strategy to validate the data.Validation can be done at a screen level or web block level. I prefer to do it in web block level and only call event to update the parent when data is valid, else just display the validation errors inside the web block.
You can choose to validate data at the end before final Save, but it can make the validation logic very complex as you would now be validating all sections of the structure.
I would leave the choice to you.
Hope this helps,
Cheers,
Saugat
if you need data from your block available in your parent, the most obvious route is to have an Event on your Block with as inputs the data from your block, and trigger that event on each change of the block data. In the parent, you'll have a handler screen action that copies that data to the parent's local variable covering the entire data set that needs to be saved when pressing the save button.
Dorine
Hello Dorine,
Thank you for the reply,
But I have number of fields in the form including tables dynamic population as a grid as well (Ex,Add record for table grid to add multiple row cells to table) ,So on a table level how the onchange will be triggered ,I mean how all data will be clubbed as a single even pass to parent screen or do I need to call each on change as there are approx 50 fields in Block and no submit button.
the OnChange needs to be triggered on each single input element that changes data that needs to be available in the parent screen.
However, you most likely only need one OnChange action/event that passes all data from the block to the parent.
So 50 fields (that's really a lot, and odd to have this in a separate block without the logic to save in the same place, and even wilder that this also involves multiple rows) will all trigger the same event in their OnChange (either the event itself or maybe an action executing the event)
Hey @Preeti zade ,
You need to handle this using onChange. Create one common Event and call that in onChange to pass the values to the parent. But make sure you handle this case using one common event and try to use a single stcuture which contains all the variables.
Thanks,
Sudip
OnParametersChanged is not triggered by block variables changing
Sorry I mistakenly typed OnParameterChange. It should be onChange. I will be careful from next time. Thank @Dorine Boudry for correcting me.
This problem is very simple and frequently encountered.
You just need to organize your main data structure on the screen, then pass it to an input block. When the data in the block changes, pass all that input to an event of the block. On the main screen, use an action to handle the block's event and then update the value of the main data structure.
With this implementation, you will retain all the screen values even if the tab changes.
Hope this helps for you!
In short... You can store the data in variables/structures on the Parent Screen and pass them to each block through Input Parameters. When users edit data inside a block, use Events/Callbacks to send the updated values back to the parent screen immediately (without a submit button in the block).
Then, use the single Save button on the Parent Screen to save all collected data at once.