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

Disable button after loading does not work #5

Open
rrelmy opened this issue Feb 19, 2019 · 2 comments
Open

Disable button after loading does not work #5

rrelmy opened this issue Feb 19, 2019 · 2 comments

Comments

@rrelmy
Copy link

rrelmy commented Feb 19, 2019

We have a problem where a state change will not be correctly reflected after a state change.
https://jsfiddle.net/gvc3ryo1/7/

Changing the loading property overrides changes on the disabled property.
I am not aware of a workaround

I suspect calling the stop method clashes with the property change
https://github.com/hakimel/Ladda/blob/1f4586f7a1f2043b3d027c8bf471d39d489da1b8/js/ladda.js#L103

@rrelmy
Copy link
Author

rrelmy commented Feb 19, 2019

I found a potential solution, not sure if it is the best idea.

If the disabled property is passed explicitly from the component to the button a unwanted state change can be detected and fixed after changing the loading property:

  props: {
    // ...
    disabled: {
      type: Boolean,
      required: false
    },
    // ...
  },
<button ... :disabled="disabled">
  watch: {
    loading: function (loading) {
      loading ? this.ladda.start() : this.ladda.stop()

      // Workaround for https://github.com/zcfan/vue-ladda/issues/5
      Vue.nextTick().then(() => {
        this.$refs.ladda.disabled = this.disabled
      })
    },
    // ...

I can create a PR if this solution would be acceptable

@zcfan
Copy link
Owner

zcfan commented Feb 26, 2019

Weird behavior... Ladda should set disable to the previous state instead of reset to true 😂

Yes please create a PR, Thank you! And you might want to correct the behavior of ladda too, I think they'll be happy someone found this bug.

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

2 participants