darrenhillconsulting
01/18/2022, 4:35 PMwarn
a user of something when they change a value on a form. So, I want to display a dialog.confirm
from the validateField
function and ask them to confirm the change .. before allowing the change on the field (which will trigger the fieldChanged function. We all know that dialog.confirm
runs asynchronously ... has anyone figured out a why to make it behave synchronously
?Matt Bernstein
01/18/2022, 4:37 PMdarrenhillconsulting
01/18/2022, 4:38 PMMatt Bernstein
01/18/2022, 4:42 PMasync checkDuplicates(options, modules) {
await modules.https.post.promise({
url: options.restletUrl,
body: {
command: "checkDuplicates",
values: JSON.stringify({
selected: this.selected.records,
selectAccountingPeriod: this.selectAccountingPeriod(),
}),
},
headers: [{"Content-Type": "application/json"}],
}).then((response) => {
this.duplicates = JSON.parse(response.body);
}).catch((e) => {
console.error("e", e);
alert("An unexpected error has occurred\n" +
` name : ${e.name || ""}\n message : ${e.message || ""}\n stack : ${e.stack}`
);
this.duplicates = [{id: -1}];
});
return this.duplicates;
}
}
this is an example i used https prmomise async and then i called in an async function and awaited the response
async saveRecord(options, modules) {
const checkDuplicatesResults = await this.checkDuplicates(options, modules);
}
It should also work for the dialogdarrenhillconsulting
01/18/2022, 5:30 PMGerald Gillespie
02/10/2022, 10:53 AMconst pendingChange={}
in client script closure
• use fieldChanged
to detect the fieldId of interest. X
• for any change for X that doesn’t have a pendingChange.X
entry…
◦ create a pendingChange.X
object that has the values of interest.
▪︎ pendingChange.X ={ fieldId : 'X', dialog : null, oldvalue: 'foo', newvalue : 'bar' }
etc
◦ create a custom dialog in that object X.dialog = dialog.create…
◦ set the buttons where the label is confirm but the value is the object. buttons : [ { label:'confirm', value : pendingChange.X}, {label : 'cancel' ,value: null}]
where confirmation returns the object you created before
◦ undo the user’s change in X.
◦ if they confirm then
will have an object you can use to update the value
◦ if they cancel then remove the entry from pendingChange
• for any change for X that does have a pendingChange[X]
entry…
◦ it must have been made by a confirmation and so just allow it
if somehow a save/submit
is initiated in the JS repl loop before the confirm runs it’s fine because afer all they didn’t confirm it. Or (i suggest don’t do this ) you could tick the save/submit at least one more time by putting the save/submit into a promise.darrenhillconsulting
02/10/2022, 4:31 PMGerald Gillespie
02/11/2022, 1:17 PMpendingChange
is in scope for fieldChanged
you could look for `pendingChange[fieldId]`and do pendingChange[fieldId].dialog.then( choice=>{ /* process choice */ })
Because they are out of the box I use dialog (and message) quite a bit and in some creative waysdarrenhillconsulting
02/11/2022, 2:18 PM