Skip to content

Added v-model support - #53

Open
salomaosnff wants to merge 2 commits into
hCaptcha:masterfrom
salomaosnff:feat/v-model-support
Open

Added v-model support#53
salomaosnff wants to merge 2 commits into
hCaptcha:masterfrom
salomaosnff:feat/v-model-support

Conversation

@salomaosnff

@salomaosnff salomaosnff commented Dec 12, 2021

Copy link
Copy Markdown

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
const token = this.hcaptcha.getResponse(this.widgetId);
const eKey = this.hcaptcha.getRespKey(this.widgetId);
this.$emit('verify', token, eKey);
this.$emit('input', token);

@DSergiu DSergiu Jan 20, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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