Update row from only form's changed value


Say I have a form this form is populated with database's data based on user's selection. After the form is filled with data user can change any field's data and then press update button. This will trigger a update single element query.

But I am facing problem to identify the 'changed' columns. Is there anything like table's changeset for form (I haven't found it) ?

Another issue is form.data gives me object like this:

notice that values are array so just doing full update will messup existing values. how can I update the element without messing up unchanged values ? Do I have to use key value pairs only ?


unchanged values become like this (casesize > was 1 > now ["1"]):

Bumping for response.

Are all of the values here from the same table? The established pattern is just to feed the update query the entire form.data object in the changeset object field.

As for the arrays, what kind of component are those coming from? If they're multi-selects and you only ever need a single value there, maybe change to the regular select component?

All the values from same table, they are text fields. I don't see changeset property in the form.

The unchanged fields values are actually passing as converted as array.

form has: Data and InitialData, we can manipulate them to achieve what is needed:

_.pickBy(form.data, (value, key) => !_.isEqual(value, form.initialData[key])) this solves the issue

1 Like

The changeset object is what's passed by the query. Using form.data here is the common practice. Unchanged values will remain the same in the DB and changes will be reflected.

iyap , unfortunately this was modifying my unchanged values too