Guest User

Untitled

a guest
Oct 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. // Проверка, чтоб были заполнены все (5 шт.) поля
  2.  
  3. let submit = [false, false, false, false, false];
  4.  
  5. //1. check title of poem
  6. document.querySelector('#stihname').onchange = function () {
  7. let stihName = document.querySelector('#stihname').value;
  8. stihName ? submit[0] = true : submit[0] = false;
  9. }
  10. // 2. check text of poem
  11. document.querySelector('#stihtext').oninput = function () {
  12. let stihText = document.querySelector('#stihtext').value;
  13. stihText ? submit[1] = true : submit[1] = false;
  14. }
  15. // 3. check genre of poem
  16. document.querySelector('.radio').addEventListener('change', () => {
  17. let radio1 = document.querySelector('#radio1');
  18. let radio2 = document.querySelector('#radio2');
  19. let radio3 = document.querySelector('#radio3');
  20. if (radio1.checked || radio2.checked || radio3.checked) {
  21. submit[2] = true
  22. } else {
  23. submit[2] = false
  24. };
  25. })
  26. //4. check name of img file
  27. let imgName = document.querySelector('#img-name');
  28.  
  29. imgName.oninput = function () {
  30. imgName.value ? submit[3] = true : submit[3] = false;
  31. }
  32. // 4.1. проверка на правильный формат имени картинки ("число-строка") через regexp
  33. imgName.onblur = function () {
  34. let arr = imgName.value.split('-');
  35. const regNum = /\d/;
  36. const regStr = /[a-z]/;
  37.  
  38. (regNum.test(arr[0]) && regStr.test(arr[1])) ? submit[3] = true : submit[3] = false;
  39. // console.log(regStr.test(arr[1]))
  40. }
  41. // 5. check if choosen file
  42. document.querySelector('#file').oninput = function () {
  43. let ChoosenFile = document.querySelector('#file').value;
  44. ChoosenFile ? submit[4] = true : submit[4] = false;
  45. }
  46.  
  47. document.querySelector('#submit').addEventListener('click', (e) => {
  48. if (!submit.every(elem => elem == true)) {
  49. e.preventDefault();
  50. }
  51. });
Add Comment
Please, Sign In to add comment