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

Added v-model support #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

salomaosnff
Copy link

@salomaosnff salomaosnff commented Dec 12, 2021

Now it is possible to get the token using v-model and also validate it with vee-validate with the required rule for example.

@e271828- e271828- requested a review from DSergiu January 20, 2022 11:43
@@ -150,13 +158,16 @@ export default {
const token = this.hcaptcha.getResponse(this.widgetId);
const eKey = this.hcaptcha.getRespKey(this.widgetId);
this.$emit('verify', token, eKey);
this.$emit('input', token);
Copy link
Contributor

@DSergiu DSergiu Jan 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v-model would allow 2way binding which I believe would not make sense for the component.

One solution could be to listen to the verify and expire events and bind the token to a local data in your parent component. e.g.

<h-captcha
  ...
  @verify="(token) => {hCaptchaToken = token}"
  @expire="hCaptchaToken =null"
/>

// use hCaptchaToken for "required" in "vee-validate"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the component doesn't accept the token as input, I think using v-model would make it simpler to use. Another alternative that would solve the same problem would be to use token.sync instead of v-model. Thus, it would not be necessary to create event-listeners and callbacks in the component call

},
onChallengeExpired() {
// vue3 will transform this `camelCase` event name into `kebab-case`
this.$emit('challengeExpired');
this.$emit('input', null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a challenge expires the token status does not change.

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

Successfully merging this pull request may close these issues.

2 participants