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

Reset form data when closing event #269

Open
worjs320 opened this issue Mar 19, 2020 · 3 comments
Open

Reset form data when closing event #269

worjs320 opened this issue Mar 19, 2020 · 3 comments

Comments

@worjs320
Copy link

hi
i want to Reset form data when closing event.
Can you answer me how?

@KOEI5113
Copy link

Here is a example from the official document :

$('#purchase-form').on($.modal.BEFORE_CLOSE, function(event, modal) {
  clear_shopping_cart();
});

Which mean when a $.modal.BEFORE_CLOSE event has been triggered, will run a function name call clear_shopping_cart. You can switch clear_shopping_cart to any code you need, such as :

$('#purchase-form').on($.modal.BEFORE_CLOSE, function(event, modal) {
    $('input[name="amount"]', $(this)).val('');
});

Which mean when a $.modal.BEFORE_CLOSE event has been triggered, will find a input element named amount which under the #purchase-form form. If you need to reset form data only when a specific modal be closed, you can using modal parameter to do some check.

Hope this will helps. Cheers!

@ivostoykov
Copy link

ivostoykov commented Jun 12, 2020

Hi,

Edit: I suppose this might be linked to #266

It seems to me that $.modal.*_CLOSE do not fire with ajax... Here is my setup

<a href="/users/new" rel="modal:open" class="btn">Add User</a>
JS - never fired

 $("a.btn").on($.modal.CLOSE, function (event, modal) {
    console.log(event);
    console.log(modal);
  });

then, let's check (lines 305, 311 (code for line 317 is omitted - the same with the other property)

  try { console.log($('a.btn').modal.isActive());  } // with the element which is wrong, but just to check
  catch (err) {
    console.log(err.message);
    console.log(err);
  }

  try {  console.log('modal.isActive: ' + $.modal.isActive());  }
  catch (err) {
    console.log(err.message);
    console.log(err);
  }

and the browser complains:

Cannot read property 'isActive' of undefined
users_ui.js:308 TypeError: Cannot read property 'isActive' of undefined
    at checkModal (some.js:305)
users_ui.js:313 Cannot read property 'isActive' of undefined
users_ui.js:314 TypeError: Cannot read property 'isActive' of undefined
    at checkModal (somejs:311)
users_ui.js:319 Cannot read property 'getCurrent' of undefined
users_ui.js:320 TypeError: Cannot read property 'getCurrent' of undefined
    at checkModal (some.js:317)

@Zenoo
Copy link

Zenoo commented Jul 3, 2021

If you check the demo, the $.modal.CLOSE event is triggered with AJAX too.

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

No branches or pull requests

4 participants