Variables not there if disabled was set and then unset

I have two buttons. The second button can’t be pressed until the first button has already been pressed. So, I’ve created a variable ‘varEnableButton’ with a value of 0. Then, as part of the action on the first button I change the value to 1. I then have a dynamic attribute of Disabled on the second button with the value being varEnableButton == 0. It works perfectly - it’s disabled on page load and then becomes enabled after the first button is clicked.

But, the rest of the action on the second button fails because the variables don’t seem to be accessible anymore. I had a Data Detail containing an ID and use this in the action of the second button. But, that GET variable isn’t there when I click the button (browser console confirms this). If I remove the Disabled attribute then it works perfectly.

Is this a bug? Do I need to go about it a different way?

Can you post your buttons code here, as i am not sure i understand what variable is not accessible when?

No problem. Here it is:

<button id="btn5" class="btn btn-primary" dmx-on:click="connEmailInvoice.load({invoiceid: data_detail1.data.InvoiceID})" dmx-bind:disabled="(varEnableEmailButton.value == 0)"><i class="fa fa-envelope-o fa-fw"></i>Send Email</button>

So what variable value is not available there?

invoiceid

The browser console shows it calling api/emailInvoice.php when it should be api/emailInvoice.php?invoiceid=123

So is this button inside some detail region? Where does data_detail1.data.InvoiceID come from exactly?

Yes, it’s inside a modal. The data detail is set when the modal is opened from a generated list. If I remove the disabled bit it works perfectly.

And how do you open the modal? By clicking the other button or is it even related?

It’s not really related. The generated list has a button on each row to open the modal which then shows the details of that record (it sets the value for the Data Detail). It’s that modal which has two buttons on it. I just want the second button to be disabled until the first button has been clicked.

Strange, do you see any errors in the console? I just tested this locally and it seems to properly pass the data detail value to the load server action event.

I get a 500 error because the server connect script requires the invoiceid to be passed to it. It shows emailInvoice.php as the script that’s called. If I remove the ‘disabled’ dynamic attribute then it correctly calls emailInvoice.php?invoiceid=123 and then works perfectly.

Can you send me a link to your page where i can check this?

I’m afraid it’s a secure CRM I’ve built. I can PM you the file?

Check if the data_detail1.data.InvoiceID value is set, place it somewhere next to or inside the button as an expression. Like

<button id="btn5" class="btn btn-primary" dmx-on:click="connEmailInvoice.load({invoiceid: data_detail1.data.InvoiceID})" dmx-bind:disabled="(varEnableEmailButton.value == 0)">
  <i class="fa fa-envelope-o fa-fw"></i>
  Send Email ({{data_detail1.data.InvoiceID}})
</button>

Is the value initially not there or does it disappear after the disabled flag is being toggled?

Ooh, you’ve nailed it. I seemed to have a rogue Data Detail set in the click action which reset it back to empty. Doh! Not sure why removing the ‘Disabled’ action resolved it previously but all is now working.

Thanks for your help @Teodor and @patrick. :slight_smile:

1 Like