victorgarciaesgi / regle

📏 Typescript first model-based form validation library for Vue 3
https://regle.vercel.app
MIT License
9 stars 0 forks source link

Get all dirty fields #5

Open martinszeltins opened 3 weeks ago

martinszeltins commented 3 weeks ago

I have a backend that expects me to send it only the dirty fields via API. I wonder if it is possible to somehow retrieve all fields of my form that are dirty?

For example if this is my form:

const form = ref<Form>({
        name: 'abc', <----- dirty
        email: '',
        skills: [
            {
                skillName: '',
                level: 0
            },
            {
                skillName: 'SuperPower', <----- dirty
                level: 0
            }
        ],
    })

I have 2 fields that are dirty here:

  1. name
  2. skills[1].skillName

It would be nice if regle had some function like getDirtyFields that would return me only those fields that are dirty like this:

{
    name: 'abc',
    skills: [
        null,   <--- this is null because skill[0] does not have ANY dirty fields

        {
            skillName: 'SuperPower'
        }
    ]
}
victorgarciaesgi commented 3 weeks ago

Yeah that would be totally possible to add!

kyong9793 commented 1 week ago

+1

victorgarciaesgi commented 1 day ago

@martinszeltins @kyong9793 , should it extract only dirty fields that are valid ? Should it perform a validate before getting the values?

martinszeltins commented 1 day ago

@martinszeltins @kyong9793 , should it extract only dirty fields that are valid ? Should it perform a validate before getting the values?

@victorgarciaesgi It should extract all dirty fields, validation is not required.