Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LittleSound opened this issue Jun 18, 2022 · 0 comments
Open

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

LittleSound opened this issue Jun 18, 2022 · 0 comments
Assignees
Labels
feature New feature or request

Comments

@LittleSound
Copy link
Owner

LittleSound commented Jun 18, 2022

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>
@LittleSound LittleSound self-assigned this Jun 18, 2022
@nekomeowww nekomeowww added the feature New feature or request label Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants