validation.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. function validateSources(list) {
  2. return list.reduce(function(acc,x) {
  3. var event = new CustomEvent('validation');
  4. event.initCustomEvent('validation',true,true,querySourceRaw(x));
  5. var el = qi(x),
  6. listener = el && el.validation,
  7. res = !listener || listener && el.dispatchEvent(event);
  8. console.log(el && el.parentNode.lastChild);
  9. if (!res) {
  10. console.log("Validation failed:" + x);
  11. scrollToValidationInputs();
  12. }
  13. //if (el) el.style.background = res ? '' : 'pink';
  14. return res && acc; },true); }
  15. (function () {
  16. function CustomEvent ( event, params ) {
  17. params = params || { bubbles: false, cancelable: false, detail: undefined };
  18. var evt = document.createEvent( 'CustomEvent' );
  19. evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
  20. return evt; };
  21. CustomEvent.prototype = window.Event.prototype;
  22. window.CustomEvent = CustomEvent; })();
  23. function scrollToValidationInputs() {
  24. const inputFields = document.querySelectorAll('.column')
  25. for (let item of inputFields) {
  26. if (item.classList.contains('error')) {
  27. const errorInputField = document.querySelector('.column.error')
  28. console.log(errorInputField)
  29. errorInputField.scrollIntoView({
  30. behavior: 'smooth',
  31. block: 'center'
  32. })
  33. }
  34. }
  35. }