5

Where could I suppress the "are you sure you want to leave this page" popup when leaving a contribution page (e.g. donation) without actually proceeding with the contribution. I realize it may be there to prevent leaving the page accidentally mid-way through filling out the form but I actually think it's more annoying than helpful in the fraction of accidental cases. Also, I have a Facebook login on the page, which, when utilized, forces the page to reload and thus invokes the 'leave this page' popup. This is confusing to the user who wouldn't know they need to hit the "leave this page" button in order to get logged in (not to mention they'll actually stay on the page, hence the confusion).

This is on Joomla (3.4.4 w/ CiviCRM 4.6.9)

I'm assuming there's an onbeforeunload function - one appears in /administrator/components/com_civicrm/civicrm/js/Common.js

The warning appears even when the user has not made any entries on the form. Shouldn't the warning only pop up when they do?

Thank you for any pointers.

  • 1
    OK, so commenting out the 'onbeforeunload' function in the file I mentioned above definitely removes the popup but the way I should have really asked the question is how could we invoke the function only when something is entered/selected in the form on the page. Because in that case it's useful. – MtnPavlas Oct 16 '15 at 22:40
  • I'd observed this behaviour once or twice lately on 4.6 sites I think, will take a moment to look into it if I see it again. It is kinda bothersome but since would have been happening when submitting or reloading, had just been hitting ESC or whatever makes it go away ASAP :D – Chris Burgess Oct 18 '15 at 8:56
2

CiviCRM uses jQuery to watch form inputs and give a warning only if there are unsaved changes. You'll find the code for it in Common.js. When I try out a sample contribution page on the demo server it looks to be working correctly; if I open a contribution page, enter nothing and close the tab, I get no warning. But if I enter an amount and then try to leave it pops up the onbeforeunload message.

If you're up for it, debugging the CRM.utils.initialValueChanged function to find out why civi thinks the form has been changed when it hasn't would be helpful feedback for us improving the software.

Or you could just add a little javascript to your FB login button. If the existing markup looks like <button type="submit"> then you could add to it so it looks like <button type="submit" onclick="window.onbeforeunload = null;">

But seriously, the debugging feedback would be helpful.

  • Thank you, Coleman, for the info. I'm not much of a developer but will look into why Civi thinks something has been changed on the form and post here for others (and for the Civi team). – MtnPavlas Oct 19 '15 at 16:06
  • Just guessing -- is it possible browser auto-fill inserts something into the form? – Laryn - CEDC.org Oct 22 '15 at 14:04
1

This happens when the built-in profile for user registration ("Name and Address" is the out-of-the-box title) is used on the contribution page. Swap it for another profile, and the pop-up does not appear. Replicated this on the Joomla CiviCRM demo site.

  • Would be good to narrow it down to the particular field in that profile that is causing it. – Coleman Oct 22 '15 at 17:37
  • Thanks for prompting the clarification, Coleman. It's not any one of the fields - I used all the same ones in a new profile that's not the built-in one for user registration, and it works perfectly. – MtnPavlas Oct 23 '15 at 17:50
  • that's... weird. – Coleman Oct 23 '15 at 18:27
  • I'm getting this error using a different profile – Yossi Nov 13 '18 at 21:39
1

In case it's of use to others: I wanted to make the recurring donation checkbox ("I want to contribute this amount every month") true (checked) by default on a particular donation form. I used the following custom javascript to do it.

After setting the value to "checked" in javascript, the .data('crm-initial-value', true) code was necessary to prevent CiviCRM from complaining about unsaved changes when navigating to a different page.

<script> 
CRM.$(function($) {
// make recurring contribution checkbox true by default
var r = $('#is_recur');
if (!r.length) { return; }
r.attr('checked', 'checked');
r.prop('defaultChecked', true);
r.prop('checked', true);
// necessary to tell Civi the default value has changed
r.data('crm-initial-value', true);
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.