-
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.
#48 fill field add rules validate name of serie
- Loading branch information
1 parent
e58e0bc
commit 66d1aa8
Showing
4 changed files
with
83 additions
and
50 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 |
---|---|---|
|
@@ -4,15 +4,16 @@ SPDX-FileCopyrightText: 2024 Marcellino Palerme <[email protected]> | |
SPDX-License-Identifier: MIT | ||
--> | ||
<script setup lang="ts"> | ||
|
||
import * as v from 'valibot'; | ||
const { t } = useI18n(); | ||
const dialog = ref<boolean>(false); | ||
const validateForm = ref(false); | ||
|
||
|
||
const nameRules = [ | ||
(v: string) => !!v || t("message.required"), | ||
(v: string) => (v && v.length <= 3) || t("message.max10"), | ||
]; | ||
const nameRules = ref([ | ||
(value: string) => | ||
useValibot(v.pipe(v.string(), v.nonEmpty(t('message.noEmpty'))),value), | ||
]); | ||
const nameSerie = ref<string>(""); | ||
|
||
/** | ||
|
@@ -34,51 +35,56 @@ function add() { | |
max-width="600" | ||
> | ||
<v-form | ||
v-model="validateForm" | ||
validate-on="lazy blur" | ||
/> | ||
<v-card> | ||
<v-card-title> | ||
<span class="headline">Add a new serie</span> | ||
</v-card-title> | ||
<v-card-text> | ||
<v-text-field | ||
v-model="nameSerie" | ||
:counter="10" | ||
:rules="nameRules" | ||
label="t('label.nameSerie')" | ||
hide-details | ||
required | ||
/> | ||
</v-card-text> | ||
@submit.prevent | ||
> | ||
<v-card> | ||
<v-card-title> | ||
<span class="headline">{{ t('title.addSerie') }}</span> | ||
</v-card-title> | ||
<v-card-text> | ||
<v-text-field | ||
v-model="nameSerie" | ||
:counter="10" | ||
:rules="nameRules" | ||
:label="t('label.nameSerie')" | ||
required | ||
/> | ||
</v-card-text> | ||
|
||
<v-expansion-panels> | ||
<v-expansion-panel | ||
:title="t('title.machine')" | ||
> | ||
<v-expansion-panel-text> | ||
helle | ||
</v-expansion-panel-text> | ||
</v-expansion-panel> | ||
<v-expansion-panel | ||
:title="t('title.mother')" | ||
> | ||
<v-expansion-panel-text> | ||
helle | ||
</v-expansion-panel-text> | ||
</v-expansion-panel> | ||
<v-expansion-panel | ||
:title="t('title.daughter')" | ||
> | ||
<v-expansion-panel-text> | ||
helle | ||
</v-expansion-panel-text> | ||
</v-expansion-panel> | ||
</v-expansion-panels> | ||
<v-btn | ||
color="primary" | ||
text="Save" | ||
@click="dialog = false" | ||
/> | ||
</v-card> | ||
<v-expansion-panels> | ||
<v-expansion-panel | ||
:title="t('title.machine')" | ||
disabled | ||
> | ||
<v-expansion-panel-text> | ||
helle | ||
</v-expansion-panel-text> | ||
</v-expansion-panel> | ||
<v-expansion-panel | ||
:title="t('title.mother')" | ||
disabled | ||
> | ||
<v-expansion-panel-text> | ||
helle | ||
</v-expansion-panel-text> | ||
</v-expansion-panel> | ||
<v-expansion-panel | ||
:title="t('title.daughter')" | ||
> | ||
<v-expansion-panel-text> | ||
helle | ||
</v-expansion-panel-text> | ||
</v-expansion-panel> | ||
</v-expansion-panels> | ||
<v-btn | ||
color="primary" | ||
text="Save" | ||
:disabled="!(validateForm === true)" | ||
@click="dialog = false" | ||
/> | ||
</v-card> | ||
</v-form> | ||
</v-dialog> | ||
</template> |
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,15 @@ | ||
import * as v from 'valibot'; | ||
|
||
export const useValibot = (schema, value) => { | ||
|
||
try { | ||
v.parse(schema, value); | ||
} catch (e) { | ||
if (e instanceof v.ValiError) { | ||
// Handle the validation error | ||
return(e.message); | ||
} | ||
} | ||
return true | ||
} | ||
|
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