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

Add blur event for validation libraries #102

Closed
pareeohnos opened this issue Aug 8, 2018 · 11 comments
Closed

Add blur event for validation libraries #102

pareeohnos opened this issue Aug 8, 2018 · 11 comments
Assignees

Comments

@pareeohnos
Copy link

pareeohnos commented Aug 8, 2018

I'm submitting a ... (check one with "x")

[ ] Bug report => search github for a similar issue or PR before submitting
[x] Feature request
[ ] Other, please describe

A PR (#22) was opened a while back adding the blur event, and you said you couldn't see a use case and that it would mean other events would need adding. In our application, there is a use case for this, and that is when using the vuelidate where validations can be triggered when a field is blurred. Currently I cannot apply this with vue-flatpickr due to this event not being registered/emit.

I don't disagree with your statement that it may make sense then to allow other events to be added such as keyboard events, however since Vue 2.4 it is possible to simply bind all listeners provided to a component via the $listeners property.

This would allow the developer to decide which listener they wish to bind rather than vue-flatpickr having to pick and choose. I don't know the all of the code, but at a quick glance it would as simple as changing the template of the component to

<input type="text" data-input v-on="inputListeners">

and adding a computed property

inputListeners() {
  let vm = this;
  return Object.assign({},
    vm.$listeners,
    {
      input: vm.onInput,
    }
  );
}

With this change, I would be able to do something like

<flat-pickr
  v-model="model"
  :config="config"
  @blur="onBlur"
  @keydown="onKeydown">
@ankurk91
Copy link
Owner

ankurk91 commented Aug 8, 2018

I know about the $listeners method. But i found it buggy.
Today itself i removed this approach from one of my package, see

I am happy to add blur event.
But you can still trigger vee-validate validations like this.

import VeeValidate from 'vee-validate';
Vue.use(VeeValidate,{
     events:'input|blur|on-close'
});

The on-close event is emitted by vue-flatpickr. Above config is global but you can also limit the config to component basis.

<flatpickr name="date" v-validate="'required'" data-vv-validate-on="input|on-close">

@pareeohnos
Copy link
Author

Ah fair enough, haven't run into any issues with it as of yet but equally haven't made a lot of use of it.
I realise that's possible on VeeValidate, but not with vuelidate. Vuelidate doesn't do any binding to inputs automatically at all, and leaves that part up to the developer.

The on-close event would work to a point, but we also allow users to manually enter the dates rather than just using the date picker, so in this scenario the on-close event would have fired before the new date had actually been entered so the blur even would be crucial here really.

@ankurk91
Copy link
Owner

ankurk91 commented Aug 8, 2018

Ah, i did not notice that you have written vuelidate.
I will add blur event soon, may be in few minutes.

@ankurk91 ankurk91 self-assigned this Aug 8, 2018
@pareeohnos
Copy link
Author

ah that would be amazing, thank you so much :)

ankurk91 added a commit that referenced this issue Aug 8, 2018
@ankurk91
Copy link
Owner

ankurk91 commented Aug 8, 2018

@pareeohnos
Released 7.0.5, cheers!!!

@ankurk91 ankurk91 closed this as completed Aug 8, 2018
@pareeohnos
Copy link
Author

awesome thank you!!

@pareeohnos
Copy link
Author

Just tried this out and it doesn't seem to work. I think what's happening is the input that the blur event is bound to is changed by flatpickr to the hidden input and thus never actually gets a blur event.

@ankurk91
Copy link
Owner

Oh no, the hidden input is nightmare.
I will look into, there is a workaround

@ankurk91 ankurk91 reopened this Aug 13, 2018
@pareeohnos
Copy link
Author

awesome thanks, sorry it took so long to report back

@ankurk91 ankurk91 changed the title Add additional events Add blur event for validation libraries Aug 15, 2018
@ankurk91
Copy link
Owner

Please update to v7.0.6 and let me know it it works for you.

@pareeohnos
Copy link
Author

Sorry for the delay, just got round to testing and it works perfectly. Thanks for the quick turn around

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

2 participants