I want to change my code in order to run the functions setMeansForm and setAtaGrpForm at the same time and on the same button. I want to keep the same logic, but it seems that's not working when i try to call each function on the same button (btnContinueMeans). I know i have to create an intermediate function to run both functions at the same time but i don't know how and i try to keep the current logic of the script.
Here the code i tried :
<script>
function setMeansForm(means) {
// Set input
setMultiSelectInput(means, '#inputMeans', '#datalistMeans', 'ul#displayMeans');
// Set button
const btnApply = document.querySelector('#btnApplyMeans');
const divContinue = document.querySelector('#continueMeans');
const btnContinue = document.querySelector('#btnContinueMeans');
btnApply.onclick = () => {
btnApply.style.display = 'none';
divContinue.style.display = '';
}
btnContinue.onclick = () => {
btnContinue.disabled = true;
new Promise((resolve, reject) => {
google.script.run
.withFailureHandler(reject)
.withSuccessHandler(resolve)
.setMeans(getItemSelected('ul#displayMeans'));
}).then(() => {
btnApply.style.display = '';
divContinue.style.display = 'none';
btnContinue.disabled = false;
});
}
}
/**
* Set behavior and data of the Ata Grp form
*/
function setAtaGrpForm(ata_grp) {
// Set input
setMultiSelectInput(ata_grp, '#inputAtaGrp', '#datalistAtaGrp', 'ul#displayAtaGrp');
// Set button
const btnApply = document.querySelector('#btnApplyMeans');
const divContinue = document.querySelector('#continueMeans');
const btnContinue = document.querySelector('#btnContinueMeans');
btnApply.onclick = () => {
btnApply.style.display = 'none';
divContinue.style.display = '';
}
btnContinue.onclick = () => {
btnContinue.disabled = true;
new Promise((resolve, reject) => {
google.script.run
.withFailureHandler(reject)
.withSuccessHandler(resolve)
.setAtaGrp(getItemSelected('ul#displayAtaGrp'));
}).then(() => {
btnApply.style.display = '';
divContinue.style.display = 'none';
btnContinue.disabled = false;
});
}
}
</script>