victorgarciaesgi / regle

Typescript first model-based validation library for Vue 3
MIT License
5 stars 0 forks source link

Get all dirty fields #5

Open martinszeltins opened 3 hours ago

martinszeltins commented 3 hours 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 hours ago

Yeah that would be totally possible to add!