Skip to content

Commit

Permalink
Форма отправки
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ckdevops committed May 27, 2024
1 parent dee9576 commit 57c0930
Show file tree
Hide file tree
Showing 2 changed files with 538 additions and 6 deletions.
527 changes: 526 additions & 1 deletion dist/js/main.js

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions src/modules/sendForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ const sendForm = () => {
const loadText = "Loading...";
const errorText = "Error!";
const successText = "Success!";
const modal = document.querySelector(".modal-callback");
const modalOverlay = document.querySelector(".modal-overlay");

const validateMinLength = (input, minLength) => {
const value = input.value.trim();
if (value.length < minLength) {
input.setCustomValidity(`Минимальная длина ${minLength} символа(ов)`);
} else {
input.setCustomValidity("");
}
};

const sendData = (data) => {
return fetch("https://jsonplaceholder.typicode.com/posts", {
Expand All @@ -23,9 +30,9 @@ const sendForm = () => {
const valueInput = document.querySelector(".required");
const formData = new FormData(form);
const formBody = {};

if (valueInput.value === "") {
alert("Необходимо ввести номер телефона");
console.log(valueInput.value.length);
if (valueInput.value.length !== 18) {
validateMinLength(valueInput, 11);
} else {
statusBlock.textContent = loadText;
form.append(statusBlock);
Expand Down

0 comments on commit 57c0930

Please sign in to comment.