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

Crash in validation mixin #446

Open
Dorpheus opened this issue Mar 8, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@Dorpheus
Copy link

commented Mar 8, 2019

A custom render function will crash on src/index.js line 574 when data() is called, because this.$options is undefined.

An alternative for line 574:

const vals = this.$options && this.$options.validations

would prevent the crash in the case that this.$options is null/undefined.

@Dorpheus

This comment has been minimized.

Copy link
Author

commented Mar 8, 2019

// ---- monkey patch workaround----
import {validationMixin} from 'vuelidate';
const _original_data_func = validationMixin.data;
validationMixin.data = function data() {
  if (this.$options) {
    return _original_data_func.apply(this);
  }

  return {};
};
@dobromir-hristov

This comment has been minimized.

Copy link
Contributor

commented Mar 18, 2019

Could you show how you are using Vuelidate? $options should be available, even in functional components with render funcs.

@Dorpheus

This comment has been minimized.

Copy link
Author

commented Mar 19, 2019

const {required} = require('vuelidate/lib/validators');
  export default {
       ...
    validations: {
      phone: {
        required, isPossibleNumber(value, vm) {
          return isPossibleNumber(value, vm.phoneCountry);
        }
      }
    }
};

template:
 input(placeholder='Mobile Phone', v-model='phone', :v='$v.phone', type='tel',
      :phoneCountry='phoneCountry', @phoneCountry='onPhoneCountry')
@dobromir-hristov

This comment has been minimized.

Copy link
Contributor

commented Mar 19, 2019

Sorry for being stupid, but how are you defining this component? Please make some sort of reproducible example.

@Dorpheus

This comment has been minimized.

Copy link
Author

commented Apr 4, 2019

Please make some sort of reproducible example.

Sorry, didnt have time to do that yet. IIRC having a v-runtime-template render on the page triggered it. I would have to take some time to reduce it down to an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.