{ "$schema": "../../schemas/code-crispies-module-schema.json", "id": "html-forms-validation", "title": "HTML-Formulare: Validierung", "description": "Lerne die eingebauten HTML5-Formular-Validierungsattribute kennen", "mode": "html", "difficulty": "intermediate", "lessons": [ { "id": "required-fields", "title": "Pflichtfelder", "description": "Das required-Attribut verhindert das Absenden des Formulars, wenn das Feld leer ist.

Füge es zu jeder Eingabe hinzu, die ausgefüllt werden muss:
<input type=\"text\" required>

Der Browser zeigt automatisch eine Validierungsmeldung an.", "task": "Mache sowohl das Name- als auch das E-Mail-Feld zu Pflichtfeldern, indem du das required-Attribut hinzufügst.", "previewHTML": "", "previewBaseCSS": "body { font-family: system-ui; padding: 20px; } form { max-width: 350px; } label { display: block; margin-top: 15px; margin-bottom: 5px; } label:first-of-type { margin-top: 0; } input { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } input:invalid { border-color: #d32f2f; } button { margin-top: 20px; padding: 10px 20px; background: #1976d2; color: white; border: none; border-radius: 4px; cursor: pointer; }", "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": "Füge das 'required'-Attribut zur Name-Eingabe hinzu" }, { "type": "attribute_value", "value": { "selector": "input[name='email']", "attr": "required", "value": true }, "message": "Füge das 'required'-Attribut zur E-Mail-Eingabe hinzu" } ] }, { "id": "input-constraints", "title": "Eingabebeschränkungen", "description": "Kontrolliere, was Benutzer eingeben können:

minlength / maxlength - Textlängenbegrenzung
min / max - Zahlenbereich
pattern - Regex-Musterabgleich
placeholder - Hinweistext (kein Label!)", "task": "Füge Validierung zur Passwort-Eingabe hinzu:
1. Füge minlength=\"8\" für die Mindestlänge hinzu
2. Füge maxlength=\"20\" für die Maximallänge hinzu
3. Füge placeholder=\"Passwort eingeben\" als Hinweis hinzu", "previewHTML": "", "previewBaseCSS": "body { font-family: system-ui; padding: 20px; } form { max-width: 350px; } label { display: block; margin-bottom: 5px; } input { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } input:invalid:not(:placeholder-shown) { border-color: #d32f2f; } small { display: block; font-size: 12px; color: #666; margin-top: 4px; } button { margin-top: 20px; padding: 10px 20px; background: #1976d2; color: white; border: none; border-radius: 4px; cursor: pointer; }", "sandboxCSS": "", "initialCode": "
\n \n \n Muss 8-20 Zeichen lang sein\n \n \n
", "solution": "
\n \n \n Muss 8-20 Zeichen lang sein\n \n \n
", "previewContainer": "preview-area", "validations": [ { "type": "attribute_value", "value": { "selector": "input[type='password']", "attr": "minlength", "value": "8" }, "message": "Füge minlength=\"8\" zur Passwort-Eingabe hinzu" }, { "type": "attribute_value", "value": { "selector": "input[type='password']", "attr": "maxlength", "value": "20" }, "message": "Füge maxlength=\"20\" zur Passwort-Eingabe hinzu" }, { "type": "attribute_value", "value": { "selector": "input[type='password']", "attr": "placeholder", "value": null }, "message": "Füge einen Placeholder hinzu, der andeutet, was einzugeben ist" } ] }, { "id": "complete-registration", "title": "Vollständiges Registrierungsformular", "description": "Erstelle ein vollständiges Registrierungsformular mit allen Validierungskonzepten:

- Pflichtfelder mit * markiert
- E-Mail-Validierung (type=\"email\" verwenden)
- Passwort mit Längenbeschränkungen
- AGB-Checkbox (Pflichtfeld)
- Absende-Button", "task": "Vervollständige das Registrierungsformular. Füge required-Attribute, passende Eingabetypen und Validierungsbeschränkungen hinzu.", "previewHTML": "", "previewBaseCSS": "body { font-family: system-ui; padding: 20px; } form { max-width: 400px; background: #f5f5f5; padding: 25px; border-radius: 8px; } h2 { margin-top: 0; margin-bottom: 20px; } label { display: block; margin-top: 15px; margin-bottom: 5px; font-weight: 500; } input[type='text'], input[type='email'], input[type='password'] { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; font-size: 14px; } input:focus { outline: 2px solid #1976d2; border-color: transparent; } input[type='checkbox'] { width: auto; margin-right: 8px; vertical-align: middle; } label:has(input[type='checkbox']) { display: flex; align-items: center; font-weight: normal; } button { width: 100%; margin-top: 20px; padding: 12px; background: #1976d2; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; font-weight: 500; } button:hover { background: #1565c0; }", "sandboxCSS": "", "initialCode": "
\n

Konto erstellen

\n \n \n \n \n \n \n \n \n \n \n \n \n \n
", "solution": "
\n

Konto erstellen

\n \n \n \n \n \n \n \n \n \n \n \n \n \n
", "previewContainer": "preview-area", "validations": [ { "type": "attribute_value", "value": { "selector": "#fullname", "attr": "required", "value": true }, "message": "Mache das Feld für den vollständigen Namen zum Pflichtfeld" }, { "type": "attribute_value", "value": { "selector": "#email", "attr": "type", "value": "email" }, "message": "Setze den Eingabetyp für E-Mail auf 'email'" }, { "type": "attribute_value", "value": { "selector": "#email", "attr": "required", "value": true }, "message": "Mache das E-Mail-Feld zum Pflichtfeld" }, { "type": "attribute_value", "value": { "selector": "#password", "attr": "type", "value": "password" }, "message": "Setze den Eingabetyp für Passwort auf 'password'" }, { "type": "attribute_value", "value": { "selector": "#password", "attr": "required", "value": true }, "message": "Mache das Passwort-Feld zum Pflichtfeld" }, { "type": "attribute_value", "value": { "selector": "#password", "attr": "minlength", "value": "8" }, "message": "Füge minlength=\"8\" zum Passwort hinzu" }, { "type": "attribute_value", "value": { "selector": "#terms", "attr": "required", "value": true }, "message": "Mache die AGB-Checkbox zum Pflichtfeld" } ] } ] }