-
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.
feat: added deep nested check for
$validate
type output
- Loading branch information
1 parent
0e775fe
commit 22bdf48
Showing
6 changed files
with
103 additions
and
44 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
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 |
---|---|---|
@@ -1,11 +1,41 @@ | ||
<template> | ||
<div>{{ r$.$fields.name.$value }}</div> | ||
<div>{{ r$.$fields.fullName.$value }}</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { required } from '@regle/rules'; | ||
import { minLength, required, email, dateBefore, and, checked } from '@regle/rules'; | ||
const { r$ } = useRegle({ name: 'hello' }, { name: { required: withMessage(required, 'foo') } }); | ||
interface Form { | ||
fullName?: string; | ||
email?: string; | ||
eventDate?: Date; | ||
eventType?: string; | ||
details?: string; | ||
acceptTC?: boolean; | ||
} | ||
const { r$ } = useRegle({ fullName: 'Hello' } as Form, { | ||
fullName: { required, minLength: minLength(6) }, | ||
email: { required, email }, | ||
eventDate: { | ||
required, | ||
dateBefore: withTooltip(dateBefore(new Date()), ({ $dirty }) => { | ||
if (!$dirty) return 'You must put a date before today'; | ||
return ''; | ||
}), | ||
}, | ||
eventType: { required }, | ||
details: { | ||
minLength: withMessage( | ||
minLength(100), | ||
({ $value, $params: [min] }) => `Your details are too short: ${$value?.length}/${min}` | ||
), | ||
}, | ||
acceptTC: { | ||
$autoDirty: false, | ||
required: withMessage(and(required, checked), 'You must accept the terms and conditions'), | ||
}, | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped></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
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