Hello, I want to change the props of a text field in another view by clicking on a button. I have created an onClick event with the command self.getParent().getSibling("Nachfrage ob reset").getChild("TextField").Props.text = "Hello"
, but I am getting the following error message.
My structure looks like this. My Button is in the container that is highlighted in blue
You can't. And it doesn't make much sense anyway: at runtime, the other view "doesn't exist", so why would you want to change its properties ?
If one is nested in the other, then you can access the instance of the inner one from the outer one.
If they're supposed to both run in different pages, you could use messages.
If the properties are supposed to be persistent, then the view doesn't matter.
What exactly are you trying to do ?
And I suggest you read this before answering: https://xyproblem.info/
I have the following dashboard to filter information. With the 'Eingaben zurücksetzen' button, I want to reset all inputs, and I have done that with the following script:
dashboard
Code to reset
#Funktion, um alle Angaben zu löschen
self.getSibling("InputQualitaetszentrum").props.value = None #Angaben zu Qualitaetszentrum löschen
self.getSibling("InputClients").props.value = None #Angaben zu Clients löschen
self.getSibling("InputModell").props.value = None #Angaben zu Modell löschen
self.getSibling("InputErgebnis").props.value = None #Angaben zu Ergebnis löschen
self.getSibling("InputEinzelergebnis").props.value = None #Angaben zu Einzelergebnis löschen
self.getSibling("Input_DTC_Device").props.value = None #Angaben zu DTC_Device löschen
self.getSibling("Input_DTC_SPN").props.value = None #Angaben zu DTC_SPN löschen
self.getSibling("Input_DTC_FMI").props.value = None #Angaben zu DTC_FMI löschen
self.getSibling("InputStartDatum").props.value = None #Angaben zu StartDatum löschen
self.getSibling("InputEndeDatum").props.value = None #Angaben zu EndeDatum löschen
self.getSibling("InputVIN").props.text = "" #Angaben zu VIN löschen
self.getSibling("InputProduktionsnummer").props.text = "" #Angaben zu Produktionsnummer löschen
Now, I also want a pop-up window to open first and ask me if I really want to reset everything. I wanted to configure an onclick event for the 'Ja' button to reset the inputs and wanted to use the same code as before, navigating from one view to another by using getParent
, getSibling
, and getChild
to navigate through the views and components.
Pop-up
My idea was to navigate to the level of the components of the other view with the 'Ja' button with following Code:
Code idea
`self.getParent().getSibling("Start Dashboard").getChild("XXX").props.value = None`
The standard way of doing this is through messages.
You'd have the popup button on click event send a message, and a message handler on the view that contains the form would catch that.
Turns out confirmation is something that's generic enough to be templatized. Here's what I suggest:
Create a view for the popup. Have it take (at least) those parameters:
- popup id : You'll use this to make sure you close the right popup when clicking buttons
- message type : That's the name of the message handler you'll have on the form. You'll use this as a parameter when calling
system.perspective.sendMessage
- display message : That's a message to display in the popup. This will probably be something like "Are you sure you want to do x ?"
This popup will contain a label or some other component used to display text. Bind it to the display message parameter.
It will also have 2 buttons, one to confirm and one to cancel.
Both buttons will call system.perspective.sendMessage
then system.perspective.closePopup
.
The difference lies in the payload passed to sendMessage
.
The confirm button will pass something like
{'confirmed': True}
and the cancel one will pass
{'confirmed': False}
Now, on the view that contains the form, right click the component that seems appropriate and add a script. I suggest doing this on the smallest container that contains all the input fields.
Add a message handler, give it a recognizable name (maybe "reset_form", something like this). This name is what you'll pass to the popup for the message_type
parameter.
This script for this handler will check the received payload if confirmed
is True
, and if that's the case run whatever script you want. In your case, reset the form's fields.
Notes:
- I suggest putting the reset code in a component method, and calling it from the message handler (so you can also call it from a "reset button", or other events if needed). It's always better to separate things anyway.
- The "confirmed: False" is not necessary in this case, so you can just close the popup when clicking the "cancel" button. BUT, in some cases it's useful to know that the confirmation was denied, so if you want to be able to reuse that popup I suggest you leave that in. You just won't use the cancel payload in your specific case.
- You can add parameters and items in the payload if needed. I know I often also include a "source identifier", that's used to differentiate between several components that are on the same view and that use the same message handler.