Skip to content

Яковлева Анастасия #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,74 @@
<body>
<main>
<h1>Найди себе друга!</h1>
<form action="/pets/orders" method="POST">
<fieldset>
<legend>Информация о питомце</legend>
<label>
Животное, которое вы хотите
<select name="petType">
<option value="dog">Собака</option>
<option value="cat">Кот</option>
<option value="tiger">Тигра</option>
</select>
</label>

<!--Форму размещай тут-->
<label>
Цвет глаз
<input type="color" name="eyeColor">
</label>

<label>
Длина хвоста
<input type="number" name="tailLength" min="7" max="120" value="7" required>
</label>
<label>
Пол животного
<label>
<input type="radio" name="gender" value="boy"> Мальчик
</label>
<label>
<input type="radio" name="gender" value="girl"> Девочка
</label>
<label>
<input type="radio" name="gender" value="none" checked> Не решил еще
</label>
</label>
</fieldset>
<fieldset>
<legend>Информация о себе</legend>
<label>
Ваше имя
<input type="text" name="name" placeholder="Введите имя" minlength="3" maxlength="50" required>
</label>

<label>
Номер телефона
<input type="tel" name="phone" class="phone" id="phone" placeholder="+7 (900) 000-00-00" required>
</label>

<label>
Email
<input type="email" name="email" placeholder="[email protected]" required>
</label>

<label>
Дата рождения
<input type="date" name="dateOfBirth" required>
</label>

<label>
<input type="checkbox" name="rules" value="true" required> Я согласен с условиями и готов принять к себе
пушистого зверька.
</label>
</fieldset>
<label class="buttons">
<input type="submit" name="submit" value="Отправить" disabled>
<input type="reset" name="reset" value="Сбросить">
</label>
</form>
</main>
<script src="validate.js"></script>
<script src="submitForm.js"></script>
</body>
</html>
73 changes: 73 additions & 0 deletions static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,77 @@ h1 {

.orders {
margin: 20px 0;
}

form {
width: 700px;
margin: 0 auto;
border: 1px solid #a7a7a7;
border-radius: 10px;
padding: 10px;
font-family: "Segoe UI", sans-serif;
color: black;
background-color: #ffffff;
}

fieldset {
padding: 10px;
margin-bottom: 10px;
border: 1px solid #2c3e50;
border-radius: 5px;
}

fieldset:last-child {
margin-bottom: 0;
}

fieldset legend {
text-align: center;
color: #2c3e50;
}

label {
display: block;
margin-bottom: 10px;
}

input, select {
border-radius: 5px;
}

input[type="text"],
input[type="color"],
input[type="tel"],
input[type="email"],
input[type="date"],
input[type="number"],
select {
width: 95%;
height: 24px;
margin-bottom: 10px;
margin-top: 10px;
padding: 2px 5px;
box-sizing: content-box;
border: 1px solid #cccccc;
}

input[type="submit"],
input[type="reset"] {
display: inline-block;
margin: 0 5px;
padding: 6px 15px;

color: #ffffff;

background-color: #2c3e50;
border: none;
}

input[type="submit"]:disabled {
opacity: 0.25;
}

.buttons {
margin-top: 10px;
text-align: center;
}
11 changes: 11 additions & 0 deletions static/submitForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let submit = document.querySelector("input[type=submit]");
let reset = document.querySelector("input[type=reset]");
let rules = document.querySelector("input[name=rules]");

rules.onchange = function () {
submit.disabled = !rules.checked;
}

reset.onclick = function () {
submit.disabled = true;
}
16 changes: 16 additions & 0 deletions static/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let telPhone = document.querySelector(".phone");
let form = document.querySelector('form');

function validatePhone() {
const regex = /\+7 \(\d{3}\) \d{3}-\d{2}-\d{2}/;
return telPhone.value.match(regex);
}

form.addEventListener("submit", (e) => {
let isValidEmail = validatePhone();
if(!isValidEmail) {
alert("Данные не валидны");
telPhone.focus();
e.preventDefault();
}
});