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

BeforeRemove event #1568

Open
chuckvincent opened this issue Jun 24, 2024 · 4 comments
Open

BeforeRemove event #1568

chuckvincent opened this issue Jun 24, 2024 · 4 comments
Labels

Comments

@chuckvincent
Copy link

Description: Is there a way to add an event before the removal of a field that could stop the removal based on some logic. Similar to the onremove User Event, but I can not find a way to stop the removal once this event is fired.

Environment Details:

  • formBuilder Version:
  • Browser:
  • OS:

Expected Behavior

Actual Behavior

Steps to Reproduce

Screenshot - (optional)

@lucasnetau
Copy link
Collaborator

That's a useful feature request.

In the mean time you could try attaching an event handler to the delete button click event and prevent it bubbling up to the stages handler in formBuilder

$('.delete-confim').on('click', e => {
    e.stopImmediatePropagation();
...

@chuckvincent
Copy link
Author

chuckvincent commented Jul 1, 2024

Thanks for the hint, but I am using a function to create the form so I am unable the register an event handler when the page loads for a class that does not exist. I am NOT a JS expert, is there a way around this?

@buttle
Copy link

buttle commented Feb 11, 2025

Hi,

That's a useful feature request.

Very useful indeed. :)

Thanks.

@buttle
Copy link

buttle commented Feb 11, 2025

I was unable to make e.stopImmediatePropagation() work unfortunately.

As a work around, this seems to do the trick :)

    formBuilder.promise.then(function(fb) {
      $('.stage-wrap').find('.delete-confirm').each(function() {
        let title = $(this).prop('title'); // i18n string
        let $btn = $(`<a class="btn del-button formbuilder-icon-cancel custom-delete-btn" title="${title}" />`)
        $(this).replaceWith($btn)
        $btn.closest('.form-field').on('click', '.custom-delete-btn', function() {
          if (/*logic here*/) {
            let field_id = $(this).closest('.form-field').prop('id')
            fb.actions.removeField(field_id);
          }
        });
      });
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants