Skip to content

Instantly share code, notes, and snippets.

@A1rPun
Created August 13, 2019 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save A1rPun/97b9164a0facbc882637915e04f88b09 to your computer and use it in GitHub Desktop.
Save A1rPun/97b9164a0facbc882637915e04f88b09 to your computer and use it in GitHub Desktop.
Angular to Vue
function checkValidity(el) {
if (el.checkValidity()) {
el.$valid = true;
el.$invalid = false;
} else {
el.$valid = false;
el.$invalid = true;
}
}
function change(e) {
const el = e.target;
el.$dirty = true;
el.$pristine = false;
checkValidity(el);
}
function blur(e) {
const el = e.target;
el.$touched = true;
el.$untouched = false;
}
export default {
name: 'v-form',
bind(el) {
el.$dirty = false;
el.$pristine = true;
el.$touched = false;
el.$untouched = true;
checkValidity(el);
el.addEventListener('change', change);
el.addEventListener('blur', blur);
},
unbind(el) {
el.removeEventListener('change', change);
el.removeEventListener('blur', blur);
},
};
import formDirective from './directives/form';
Vue.directive('form', formDirective);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment