on 09-28-2022 11:37 AM
Hi forum!
In a table with different rows each representing a person with name, age etc. there is a button 'CONNECT' on each of these rows which will allow one user to connect with others.
Now, when I press CONNECT on one row, I would like to bring up a dialog popup, with the name of the user clicked asking for a confirmation of connection. I've managed to do this, but the issue is, if I'm pressing Cancel on the dialog and press CONNECT on another row, the data and the name remains always of the first user clicked - until refresh the page or move to another and come back again:
onButtonPress: function(oEvent) {
const oItem = oEvent.getSource()
const oContext = oItem.getBindingContext("myModel")
const sPath = oContext.getPath()
const person = oContext.getModel().getProperty(sPath)
// outside of the Dialog logic the data is always correct
// gets the data of item clicked everytime
console.log(person.name)
if (!this.oRejectDialog) {
this.oRejectDialog = new Dialog({
title: "Please Confirm",
type: DialogType.Message,
content: [
new Label({
// inside of the Dialog logic the data is right only once
// that's when the the Dialog opens for the first time after a refresh
text: `Are you sure you want to connect with ${person.name}`,
labelFor: "connectNote"
}),
new TextArea("connectNote", {
width: "100%",
placeholder: "Add note (optional)"
})
],
beginButton: new Button({
type: ButtonType.Emphasized,
text: "Connect",
press: function() {
this.oRejectDialog.close();
}.bind(this)
}),
endButton: new Button({
text: "Cancel",
press: function() {
this.oRejectDialog.close()
}.bind(this)
})
});
}
this.oRejectDialog.open()
}
Can somebody please explain why this is happening and how to solve this?
Many thanks
quick dirty way is to destroy the dialog after close
or you use binding to get data from current row
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The data from current row is correctly received when onButtonPress
onButtonPress: function(oEvent) {
const oItem = oEvent.getSource()
const oContext = oItem.getBindingContext("myModel")
const sPath = oContext.getPath()
const person = oContext.getModel().getProperty(sPath)
// outside of the Dialog logic the data is always correct
// gets the data of item clicked everytime
console.log(person.name)
if (!this.oRejectDialog) {
this.oRejectDialog = new Dialog({
title: "Please Confirm",
type: DialogType.Message,
content: [
new Label({
// inside of the Dialog logic the data is right only once
// that's when the the Dialog opens for the first time after a refresh
text: `Are you sure you want to connect with ${person.name}`,
labelFor: "connectNote"
}),
new TextArea("connectNote", {
width: "100%",
placeholder: "Add note (optional)"
})
],
beginButton: new Button({
type: ButtonType.Emphasized,
text: "Connect",
press: function() {
this.oRejectDialog.close();
}.bind(this)
}),
endButton: new Button({
text: "Cancel",
press: function() {
this.oRejectDialog.close()
}.bind(this)
})
});
}
this.oRejectDialog.open()
}
The problem as you can see above is inside the Dialog.
quick dirty way is to destroy the dialog after close
When you say this you mean using some Method like destroyContent? if yes, this should go as new method in the constructor or separate?
Thanks
Define the afterClose event for the Dialog control and in this event handler, check if the user has pressed the Cancel button. If yes, then clear the user name in the dialog so that it updates the correct value after selecting another table entry and clicking connect.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, you can declare the afterClose event as one of the properties of the Dialog control. I believe that you would have used data binding between the control(s) used to display the user detail(s) and a model in your code - just set the corresponding model properties to blank ("") in the event handler to clear the previously displayed values upon closing the dialog.
I don't know if I did the right thing, but it is still not working.
I'm resetting the object which provides the name in the afterClose event to an empty object, (in theory this will also reference the model?!) I'm logging it in the same event and it's {}, next time I open the dialog, the object gets recreated with the correct values of the item clicked (again logged the correct values), but the text in the Dialog stays the same as for the first item clicked, not updating, it's driving me nuts.
User | Count |
---|---|
74 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.