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

Indicator and disable for form submit #220

Closed
sergeyzorin opened this issue Sep 18, 2017 · 8 comments
Closed

Indicator and disable for form submit #220

sergeyzorin opened this issue Sep 18, 2017 · 8 comments

Comments

@sergeyzorin
Copy link

Buttons have great build-in functionality - when triggered, display loading indicator and set 'disabled' class

But if I have a form with submit button:
<form ic-post-to="/items/add" ic-target="#items">
..fields...
<button type="submit">Add <i class="fa fa-spinner fa-spin"></i></button>
</form>

And click 'Add' button - no indicator and no diasble. Becouse not submit was triggered , but the form itself.

Forms with submits is very common use-case, is there way to automatically display indicator and disable submit-buttons then submitting form?

Currently, indicator can be displayed via ic-indicator attribute at form, a little clumsy, but ok. But how to declaratively disable submit button?

@ninthspace
Copy link

I do it like this:

$(document).on('beforeSend.ic', function (event, el, data) {
  if (el.is('form')) {
    // disable button
    el.find('input[type="submit"], button[type="submit"]').prop('disabled', disable);
    
    // ensure we don't submit if already submitted
    if (el.hasClass('form-submitted')) {
        event.preventDefault();
    } else {
      // show spinner
      const spinner = el.find('.fa-spinner');
      if (spinner) {
          spinner.show();
      }
      el.addClass('form-submitted');
    }
  }
});

@1cg 1cg added the enhancement label Jul 5, 2018
@1cg
Copy link
Contributor

1cg commented Jul 5, 2018

This should be part of the default behavior for forms. I will look at adding it.

@zodman
Copy link

zodman commented May 2, 2019

on the code disabled css class is added.

https://github.com/intercoolerjs/intercooler-js/blob/master/src/intercooler.js#L343

Must be a disabled property!

@zodman
Copy link

zodman commented May 2, 2019

PR #284

small demo

@zodman
Copy link

zodman commented Aug 5, 2019

some news about this ?

@1cg
Copy link
Contributor

1cg commented Aug 8, 2019

Hi @zodman I have looked into this. It looks like the disabled attribute only apply to inputs:

https://www.w3schools.com/tags/att_disabled.asp

Not to forms. Do you have a link specifying otherwise?

@zodman
Copy link

zodman commented Aug 8, 2019

let me edit the PR to apply to all inputs.. wait for it.

@zodman
Copy link

zodman commented Aug 8, 2019

patch apply!

@1cg 1cg closed this as completed May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants