Tagged: 

Viewing 5 reply threads
  • Author
    Posts
    • #7127
      mattkl
      Participant

      I’ve searched in the forums and on google and have not been able to find an answer – so my apologies if this has been addressed.

      I am using the add-more flag on a project and have realized that there is no confirmation before removing items. I.e.: if the user clicks the “-” button, there is no confirmation or warning. I would like to have a confirmation, since there is no undo function and since the button is close enough to the “+” button to allow for accidental clicks. Is there a way to add a confirmation dialog before allowing a field/group to be removed? Or, could the “-” be tied conditionally to another field? For example, the user must first click a “delete this item” checkbox before the “-” button will function.

    • #7131
      Steve
      Keymaster

      @mattkl– Welcome to the Piklist community!

      Currently, there is no option to present a confirmation message when changing. You may be able to do it with jQuery, but I haven’t tried.

    • #7133
      mattkl
      Participant

      I think that would work. Now I just have to figure out how to load jquery to the admin (post edit) area without breaking the meta-box.

    • #7135
      mattkl
      Participant

      Ok. Took me a beat to figure this out, since jquery is already in the admin section. You just have to replace $ with jQuery.

      Here is what I am using. It works (so far) for me.

      jQuery(document).ready(function () {
              jQuery(document).on("click", ".piklist-addmore-remove", function (event) {
                  return confirm("Are you sure you want to remove this item/section?");
              });
      
          });
    • #7136
      mattkl
      Participant

      Actually, you don’t need the jQuery(document).ready part…

      jQuery(document).on("click", ".piklist-addmore-remove", function (event) {
          return confirm("Are you sure you want to remove this item/section?");
      });
    • #7138
      mattkl
      Participant

      Provided that the class of the remove elements is always ‘piklist-addmore-remove’, then this binds to all existing occurrences of the removal buttons, as well as any new occurrences of the removal buttons.

      Further, it acts on all removal buttons in the page, regardless of which meta-box they are in. That may or may not be what others will want. In those cases, you would specify the meta-box ID or some container element to restrict this being added to only that specific group.

Viewing 5 reply threads
  • You must be logged in to reply to this topic.