button changes to disabled

button changes to disabled

by Daniele Cordella -
Number of replies: 6
Picture of Core developers Picture of Plugin developers

Hello.

May I ask why, in the attached all-in-one example, the procedure to export 'multiplication table' to excel changes the mform button status to disabled.

Thanks in advance.


(to execute the code, copy the file to your moodle test site wwwroot and visit moodle/test_form.php)


Average of ratings: -
In reply to Daniele Cordella

Re: button changes to disabled

by Andreas Grabs -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

Hi Daniele,

I am not that sure but it seems it has to do with the default behaviour of the submit buttons. They all are set to disabled on the submit event. And while the page is not reloaded but instead the download is started, all js actions are stopped and the disabled attribute is not removed.

Try that:

In your line 57 change

$mform = new test_form(new moodle_url('/test_form.php'));

To

$mform = new test_form(new moodle_url('/test_form.php'), null, 'post', '_blank');

After that, the button is enabled after the click.

Best regards
Andreas

Average of ratings: Useful (1)
In reply to Andreas Grabs

Ri: Re: button changes to disabled

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Thanks Andreas for your WORKING solution.
I also did some more investigations
and I found that the issue may be deeper because...

using my newly attached test file I found that
- if I download to excel the button gets disabled
but
- if I download to csv the button status does not change.

mmmmhhhhhhh
In reply to Daniele Cordella

Re: Ri: Re: button changes to disabled

by Andreas Grabs -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

Hi Danielle,

that really is strange. Maybe there are different headers while sending the output and one header makes the browser stop the js execution.

Best regards Andreas

In reply to Andreas Grabs

Re: button changes to disabled

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Moodle forms have protection, to stop them being submitted twice if the button is double-clicked. See MDL-38555. What you are seeing is probably a side-effect of that.
In reply to Daniele Cordella

button changes to disabled

by Paul Holden -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi Danielle, you can disable the double form submit protection easily - see same solution in MDL-71837
In reply to Paul Holden

Ri: button changes to disabled

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Fantastic!
Thank you Andreas, Tim and Paul.
I found a solution in
https://integration.moodle.org/job/Precheck%20remote%20branch/108349/artifact/work/patchset.diff
and it works like a charm.

In spite of this my doubt is still alive: why do I get a form protection side effect if I download to xls and I DO NOT GET any side effect when downloading to csv?