LittleSound / LittleSound/slimeform

feat(useField): rule checking and status management of fields

Open
#39 0 comments 0 reactions 1 assignee View on GitHub

@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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.