{% extends 'base.html.twig' %} {% block title %}FormField - Molécules - Design System - Bubul{% endblock %} {% block body %}
Une molécule combine plusieurs atomes pour créer un composant fonctionnel réutilisable. Elle encapsule la logique de composition.
Le composant FormField encapsule un label, un champ de saisie et les messages d'aide/erreur en une seule inclusion. Il gère automatiquement l'accessibilité (for/id).
{% verbatim %}{# Avant : 10+ lignes par champ #}
{% if error %}{{ error }}
{% endif %}
{# Après avec FormField : 1 inclusion #}
{% include '_molecules/form/form-field.html.twig' with {
name: 'email',
label: 'Adresse email',
type: 'email',
placeholder: 'votre@email.com',
required: true,
error: form_errors
} %}{% endverbatim %}
templates/_molecules/form/form-field.html.twig
Démonstration de la réutilisabilité
{% verbatim %}{% endverbatim %}
Validation côté serveur
type: 'text'
type: 'email', icon: 'mail'
type: 'password', icon: 'lock'
type: 'search', srOnly: true
type: 'textarea', rows: 4
type: 'file', accept: '.pdf,.doc'
type: 'file', multiple: true
dropzone: true, maxSize: '20 MB'
dropzoneText: '...', dropzoneHint: '...'
required: true
optional: true
disabled: true
hint: 'Texte d\'aide'
error: 'Message d\'erreur'
labelTooltip: 'Info'
| Paramètre | Type | Défaut | Description |
|---|---|---|---|
name |
string | '' |
Nom du champ (requis) |
label |
string | null |
Texte du label |
type |
string | 'text' |
text, email, password, textarea, number, etc. |
placeholder |
string | '' |
Texte placeholder |
value |
string | '' |
Valeur initiale |
required |
bool | false |
Champ obligatoire (*) |
optional |
bool | false |
Affiche "(optionnel)" |
disabled |
bool | false |
Champ désactivé |
error |
string | null |
Message d'erreur |
hint |
string | null |
Texte d'aide |
icon |
string | null |
Nom de l'icône Solar |
iconPosition |
string | 'left' |
left, right |
size |
string | 'md' |
sm, md, lg |
variant |
string | 'default' |
default, filled |
srOnly |
bool | false |
Label masqué (screen readers) |
labelTooltip |
string | null |
Tooltip sur le label |
rows |
number | 4 |
Lignes (textarea only) |
| Parametres type: file | |||
accept |
string | null |
Types acceptes (ex: '.pdf,.doc') |
multiple |
bool | false |
Autoriser plusieurs fichiers |
dropzone |
bool | false |
Mode drag & drop |
maxSize |
string | null |
Taille max affichee (ex: '20 MB') |
dropzoneText |
string | 'Glissez...' |
Texte principal dropzone |
dropzoneHint |
string | 'ou cliquez...' |
Texte secondaire dropzone |