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

Required flag is removed on reset() #2323

Closed
rklfss opened this issue Sep 12, 2019 · 1 comment
Closed

Required flag is removed on reset() #2323

rklfss opened this issue Sep 12, 2019 · 1 comment
Labels
🐛 bug Unintended behavior

Comments

@rklfss
Copy link

rklfss commented Sep 12, 2019

Versions

  • vee-validate: 3.0.4
  • vue: 2.6.10

Describe the bug

If you call reset() on a ValidationProvider, a possible "required" flag is removed.

reset() {
this.messages = [];
this.initialValue = this.value;
const flags = createFlags();
this.setFlags(flags);
this.validateSilent();
},

Here a new default flags object is created but the required flag is not set again.

To reproduce
Go to https://codesandbox.io/s/vue-template-0vcyi and click the reset button in the example. The asterisk is removed.

Expected behavior
Only reset flags that are related to the validation state.

Current Workaround

Hacky, but works...

// bugfix: required flag is removed on reset
ValidationProvider.mixin({
  created(this: InstanceType<typeof ValidationProvider>)
  {
    this.reset = ((orig: () => void) =>
      {
        return () =>
          {
            orig.call(this);
            // Trigger the watcher
            const forceRequired = this.forceRequired;
            this.forceRequired = !forceRequired;
            this.forceRequired = forceRequired;
            // set the flag
            const triggerRequireFlag = this.isRequired;
          };
      })(this.reset);
  },
});
@logaretm logaretm added the 🐛 bug Unintended behavior label Sep 12, 2019
@logaretm
Copy link
Owner

Thanks for reporting this, the fix should be in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants