Created
August 13, 2019 09:40
-
-
Save A1rPun/97b9164a0facbc882637915e04f88b09 to your computer and use it in GitHub Desktop.
Angular to Vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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