-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c23f7b
commit 5f24930
Showing
8 changed files
with
635 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,53 @@ | ||
<script lang="ts" setup> | ||
import { ref } from 'vue' | ||
import PasswordField from '@/components/PasswordField/PasswordField.vue' | ||
const password = ref<string | null>(null) | ||
const passwordFieldRef = ref() | ||
const customRule = [ | ||
{ | ||
type: 'minLength', | ||
options: { | ||
length: 10, | ||
message: 'Le mot de passe doit contenir au moins 10 caractères.', | ||
successMessage: 'Le mot de passe a une longueur valide.', | ||
}, | ||
}, | ||
] | ||
const handleSubmit = () => { | ||
// Appeler la méthode exposée `validateOnSubmit` via la référence | ||
const isValid = passwordFieldRef.value?.validateOnSubmit() | ||
if (!isValid) { | ||
alert('Corrigez les erreurs avant de soumettre !') | ||
} | ||
else { | ||
alert('Formulaire soumis avec succès !') | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<main> | ||
<v-form | ||
class="mx-16 my-6" | ||
@submit.prevent="handleSubmit" | ||
> | ||
<PasswordField | ||
ref="passwordFieldRef" | ||
v-model="password" | ||
:custom-rules="customRule" | ||
is-validate-on-blur | ||
outlined | ||
required | ||
/> | ||
<button type="submit"> | ||
Soumettre | ||
</button> | ||
</v-form> | ||
</main> | ||
</template> | ||
|
||
<style scoped> | ||
/* Add any styles you need for the playground here */ | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {Canvas, Meta, Controls, Source} from '@storybook/blocks'; | ||
import * as PasswordFieldStories from './PasswordField.stories'; | ||
import PasswordField from './PasswordField.vue'; | ||
|
||
<Meta title="Composants/Formulaires/PasswordField" component={PasswordField}/> | ||
|
||
# PasswordField | ||
|
||
Le composant `PasswordField` est utilisé pour afficher un champ de saisie de mot de passe et gérer sa validation. | ||
Il permet également d’afficher ou de masquer le contenu du champ à l’aide d’une icône. | ||
|
||
<Canvas story={{height: '150px'}} of={PasswordFieldStories.Default}/> | ||
|
||
# API | ||
|
||
<Controls of={PasswordFieldStories.Default}/> | ||
|
||
## Utilisation de base | ||
|
||
<Source | ||
dark | ||
code={` | ||
<script setup lang="ts"> | ||
import {ref} from 'vue' | ||
import PasswordField from './PasswordField.vue' | ||
const password = ref('') | ||
const passwordFieldRef = ref() // Référence Vue pour accéder au composant enfant | ||
function handleSubmit() { | ||
// Appeler la méthode exposée validateOnSubmit via la référence | ||
const isValid = passwordFieldRef.value?.validateOnSubmit() | ||
if (!isValid) { | ||
alert('Veuillez corriger les erreurs avant de soumettre.') | ||
} else { | ||
alert('Formulaire soumis avec succès !') | ||
} | ||
} | ||
</script> | ||
<template> | ||
<form @submit.prevent="handleSubmit"> | ||
<PasswordField | ||
ref="passwordFieldRef" | ||
v-model="password" | ||
outlined | ||
:is-validate-on-blur="true" | ||
/> | ||
<button type="submit">Soumettre</button> | ||
</form> | ||
</template> | ||
`} | ||
/> | ||
|
||
--- | ||
|
||
## Gestion de la validation | ||
|
||
### Validation par défaut | ||
|
||
- **required** : Si `true`, le champ est obligatoire et affiche une erreur si le champ est vide. | ||
- **isValidateOnBlur** : Si `true`, la validation se déclenche automatiquement lors du blur (perte de focus). | ||
|
||
### Règles de validation personnalisées (props `customRules`) | ||
|
||
Vous pouvez définir des règles de validation personnalisées sous forme de tableau d’objets. | ||
|
||
Pour savoir comment utiliser les regles personnalisees, veuillez consulter la section [Comment utiliser les rules](/docs/guide-du-dev-comment-utiliser-les-rules--docs). | ||
|
||
|
||
|
||
|
Oops, something went wrong.