We are currently working on a mechanism that allows users to click on any row, which then opens a new view based on the row description. This functionality is working as expected. However, we've encountered an issue where users can lose their entered information if they change the row selection. To address this problem, we've implemented a warning popup to hold users in their current view.
Here's how the script works, which runs on the 'onSelectionChange' event of the table (even though I acknowledge that it might not be the optimal event, as it only triggers when there's a row selection change, similar to 'onRowClick'):
#onSelectionChange event script on Table
def runAction(self, event):
logger = system.util.getLogger("myLogger")
# Get the currently selected row index
selected_row_index = self.props.selection.selectedRow
# Get the previously saved row index
previous_row_index = self.custom.preSelectedRow
# Log the selected and previous row indices for debugging
logger.info("Selected Row Index: %s, Previous Row Index: %s" % (selected_row_index, previous_row_index))
# Check if the current and previous row indices are different
if selected_row_index != previous_row_index:
# The selected row index has changed, open the warning popup
popup_params = {
"id": "01",
"view": "TestYP/Template/WarningPopup"
}
# Open the warning popup and store the result in a variable
popup_result = system.perspective.openPopup(**popup_params)
# Check the result of the popup (assuming it returns True or False)
if popup_result == True:
# User selected True, so do not change the row selection
logger.info("User chose to stay on the current row.")
# Restore the previous row selection
self.props.selection.selectedRow = previous_row_index
else:
# User selected False or closed the popup, allow the row to change
logger.info("Row Index Changed!")
# Save the current selected row index to the custom property for the next run
self.custom.preSelectedRow = selected_row_index
- It retrieves the currently selected row index in the table
- Retrieves the previously saved row index, for comparison
- Logs both the selected and previous row indices for debugging purposes
- It checks if the current and previous row indices are different
* If they are different, it attempts to open a warning popup, expecting a True/False response
* If the user selects 'True' in the popup, it prevents the row selection from changing and keep the previous row selection - where I'm struggling
* If the user selects 'False' or closes the popup, it allows the row selection to change - Finally, it saves the current selected row index as the previous row index for future reference
Now, my question to achieve the desired behavior is:
How can we modify this script or choose the correct event to ensure that the table row selection does not change until we receive a 'True' or 'False' input from the popup?
I'm also open to explore better solutions if this approach might not work.