// функция popupOpen
function popupOpen(event) {
const popupNew = document.querySelector("#new-card"); //форма добавления карточки
const popupEdit = document.querySelector("#edit-profile");
const formEditUserName = formEdit.elements.username;
const formEditUserDesc = formEdit.elements.userdesc;
const userText = document.querySelector(".user-info__name").textContent;
const userDescText = document.querySelector(".user-info__job").textContent;
if (event.target.classList.contains("user-info__edit-button")) {
popupEdit.classList.toggle("popup_is-opened");
formEditUserName.value = userText;
formEditUserDesc.value = userDescText;
resetErrorMessages(formEdit);
}
if (event.target.classList.contains("user-info__button")) {
popupNew.classList.toggle("popup_is-opened");
disableButton(submitButton);
form.reset();
resetErrorMessages(form);
}
}
// функция isValid
function isValid(elementToCheck) {
const errorElement = document.querySelector(`#error-${elementToCheck.name}`);
if (!elementToCheck.validity.valid) {
if (
elementToCheck.value.length <= Number(elementToCheck.getAttribute("minlength")) ||
elementToCheck.value.length >= Number(elementToCheck.getAttribute("maxlength"))
) {
if (elementToCheck.validity.valueMissing) {
errorElement.textContent = "Это обязательное поле";
} else {
errorElement.textContent = "Длина должна быть от 2 до 30 символов";
}
if (elementToCheck.validity.typeMismatch) {
errorElement.textContent = "Здесь должна быть ссылка";
}
}
return false;
} else {
errorElement.textContent = "";
return true;
}
}