LittleSound / LittleSound/slimeform
feat(useField): rule checking and status management of fields
Open
@LittleSound is already working on this.
Since Jun 18, 2022.
feature
- Dominant language
- TypeScript
- Stars
- 267
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
Rule validation and state management of form fields are placed in a separate input component, which can be used alone or in combination with the main useForm
Code Demo:
Maybe there will be a better way to design?
<!-- MyForm.vue -->
<script setup>
import { useForm, toField } from 'slimeform'
const { form, status, isError } = useForm({
form: () => ({
phone: '+86****',
}),
rule: {
phone: [
// Additional rules for purpose of business logics
]
},
})
</script>
<InputPhone v-model="form.phone" :field="toField(form, 'phone')" />
<!-- InputPhone.vue -->
<script setup>
import { useField } from 'slimeform'
const props = defineProps()
const emits = defineEmits()
const vmPhone = useVModel(props, 'modelValue', emits)
const { field: phone, state, isError, reset } = useField(vmPhone, props.field, {
rule: [
// As for mobile phone number input validations, there can be general rules
phoneFormat(),
phoneLength(),
]
})
</script>
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.