{ "$schema": "../../schemas/code-crispies-module-schema.json", "id": "html-forms-validation", "title": "Валідація форм", "description": "Використовуйте вбудовану валідацію HTML5 для кращого досвіду користувача", "mode": "html", "difficulty": "beginner", "lessons": [ { "id": "required-fields", "title": "Обов'язкові поля", "description": "Атрибут required запобігає відправці форми, якщо поле порожнє. Браузер автоматично показує повідомлення валідації - без JavaScript!

Додайте його до будь-якого поля, яке має бути заповнене:
<input type=\"text\" required>", "task": "Зробіть обидва поля (ім'я та email) обов'язковими, додавши атрибут required до кожного поля.", "previewHTML": "", "previewBaseCSS": "body { font-family: system-ui; padding: 20px; } form { max-width: 320px; } label { display: block; margin-top: 15px; margin-bottom: 5px; font-weight: 500; } label:first-of-type { margin-top: 0; } input { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 6px; box-sizing: border-box; } input:focus { outline: 2px solid steelblue; border-color: transparent; } button { margin-top: 20px; padding: 10px 20px; background: steelblue; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: 500; }", "sandboxCSS": "", "initialCode": "
\n \n \n \n \n \n \n \n
", "solution": "
\n \n \n \n \n \n \n \n
", "previewContainer": "preview-area", "validations": [ { "type": "attribute_value", "value": { "selector": "input[name='name']", "attr": "required", "value": true }, "message": "Додайте required до поля імені" }, { "type": "attribute_value", "value": { "selector": "input[name='email']", "attr": "required", "value": true }, "message": "Додайте required до поля email" } ] } ] }