Guest User

Untitled

a guest
Aug 25th, 2019
69
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkValidity(el) {
  2. if (el.checkValidity()) {
  3. el.$valid = true;
  4. el.$invalid = false;
  5. } else {
  6. el.$valid = false;
  7. el.$invalid = true;
  8. }
  9. }
  10.  
  11. function change(e) {
  12. const el = e.target;
  13. el.$dirty = true;
  14. el.$pristine = false;
  15. checkValidity(el);
  16. }
  17.  
  18. function blur(e) {
  19. const el = e.target;
  20. el.$touched = true;
  21. el.$untouched = false;
  22. }
  23.  
  24. export default {
  25. name: 'v-form',
  26. bind(el) {
  27. el.$dirty = false;
  28. el.$pristine = true;
  29. el.$touched = false;
  30. el.$untouched = true;
  31. checkValidity(el);
  32. el.addEventListener('change', change);
  33. el.addEventListener('blur', blur);
  34. },
  35. unbind(el) {
  36. el.removeEventListener('change', change);
  37. el.removeEventListener('blur', blur);
  38. },
  39. };
RAW Paste Data