Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#904 - undo part of 13333 #14145

Merged
merged 1 commit into from
Apr 29, 2019
Merged

Conversation

demeritcowboy
Copy link
Contributor

Overview

See https://lab.civicrm.org/dev/core/issues/904. The Save and New button on a new case doesn't work fully after 13333.

@civibot
Copy link

civibot bot commented Apr 27, 2019

(Standard links)

@civibot civibot bot added the 5.13 label Apr 27, 2019
@eileenmcnaughton
Copy link
Contributor

@mattwire @colemanw Can you review this potential regression

@mattwire
Copy link
Contributor

@demeritcowboy This is pretty vague. What Civi version. How does it "break"?

@demeritcowboy
Copy link
Contributor Author

@mattwire Create a new case and at the bottom of the new case form click "Save and New". It doesn't go to a new case form. I believe this would have the same problem on any form that has more than one submit button. It can be reproduced on dmaster.demo.

@mattwire
Copy link
Contributor

Ok, @demeritcowboy I can reproduce because of the silly way opencase tries to detect the 2nd button. We definitely don't want to remove submitOnce from the "save" button and I feel like not redirecting to a new case is less serious that accidently creating multiple cases... However the actual failure occurs here: https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/Form/Activity/OpenCase.php#L350 We can differentiate between the two buttons by checking for the existence of _qf_Case_upload or _qf_Case_upload_new in the submitValues array of the form object. Happy to review and merge a PR that does that.

@demeritcowboy
Copy link
Contributor Author

Hi @mattwire I looked but I don't see that there's anything to differentiate in the submitted values either in $form or $params. In js/common.js submitOnce() where it calls form.submit(), I think maybe that's the equivalent of clicking the default button, regardless of what was clicked.

Maybe in the meantime we can compromise and just remove it from the "Save and New" button and leave it on the "Save" button? That way both buttons will still work for now.

@demeritcowboy demeritcowboy changed the title undo part of 13333 dev/core#904 - undo part of 13333 Apr 27, 2019
@mattwire
Copy link
Contributor

mattwire commented Apr 28, 2019

@demeritcowboy We'll run into this issue anywhere else there are more than one submit buttons (just activities currently I think).

Can you try this?

/**
 * Function to change button text and disable one it is clicked
 * @deprecated
 * @param obj object - the button clicked
 * @param formID string - the id of the form being submitted
 * @param string procText - button text after user clicks it
 * @return bool
 */
var submitcount = 0;
/* Changes button label on submit, and disables button after submit for newer browsers.
 Puts up alert for older browsers. */
function submitOnce(obj, formId, procText) {
  // if named button clicked, change text
  if (obj.value != null) {
    cj('input[name=' + obj.name + ']').val(procText + " ...");
  }
  var form = cj(obj).closest('form');
  form.attr('data-warn-changes', 'false');
  if (document.getElementById) { // disable submit button for newer browsers
    cj('input[name=' + obj.name + ']').attr("disabled", true);
    var tmpButtonElement = cj("<input type='hidden'/>");
    // clone the important parts of the button used to submit the form.
    tmpButtonElement
      .attr("name", obj.name)
      .appendTo(form);

    form.submit();
    tmpButtonElement.remove();

    return true;
  }
  else { // for older browsers
    if (submitcount == 0) {
      submitcount++;
      return true;
    }
    else {
      alert("Your request is currently being processed ... Please wait.");
      return false;
    }
  }
}

@demeritcowboy
Copy link
Contributor Author

I ** AM ** willing to help out here and try some things, but that should probably be against master. All I'm asking for the RC is to remove the thing that made the button stop working until it can be looked at closer. To be honest I'm not sure how this turned into my problem to solve, but I do promise to test that javascript and take a run at it. @mattwire

@eileenmcnaughton
Copy link
Contributor

@mattwire given this is a very recent regression our default response should be to revert in the rc & re-fix the original bug in master. Would doing so here cause problems other than removing the fix until we have a better fix

Also @colemanw

@mattwire
Copy link
Contributor

@demeritcowboy Save/Save and New submitOnce only on "New case" currently but we want to add it elsewhere where we have the same problem eg. "New Membership" so would be good to fix properly. I'm going to merge this based on @eileenmcnaughton comments but would be really happy if you were able to find some time to review the proposed js change and PR it for master so we can have it fixed properly.

@mattwire mattwire merged commit d3fb65a into civicrm:5.13 Apr 29, 2019
@demeritcowboy
Copy link
Contributor Author

@mattwire The js doesn't work as-is but I have some ideas. Will keep you posted.

@demeritcowboy demeritcowboy deleted the submitOften branch April 29, 2019 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants