GUI - changing values before adding records

As an example. I am using GUI to add records to a table from a form. Despite my DB being auto increment for id, the GUI is passing blank id values as 0 on the form.
Where and how is best place to handle changing the data before i submit. Code on submit button query or as validation on the input box. I am using the same form for edit and adding values. i was looking to add this in the submitquery.
{
...TenScheduleForm.data,
id: TenScheduleForm.data.id === 0 ? null : TenScheduleForm.data.id
}
same would apply if I want to set certain values before adding them.

2 Likes

I would place the ID check for 0 in the submit query, but I would also make that field hidden in the form since I don’t want users trying to change an ID (I’m assuming this is a generated PK in your DB). I usually stick to field validations in the form only to force users to enter values if something can’t be NULL or needs a particular format that I can’t otherwise manage in the submit.

I’m guessing you have the field as a numeric input and have not set it as allowing null (somewhat confusingly set in the validations settings) which is why it is defaulting to zero. Might be worth changing to allow it to be null if you are going to use the form for entry as well as edit.

Hi Thanks so yes it is a numeric. The only difficulty is that if i use the Gui for bulk upsert which works on updates to current data but on any new rows added it seems to always place 0 as id.
in the submit query since i use GUI bulk upsert, I have tried to use transform function as follows:

transformData(data) {
return data.map(item => ({
...item,
id: item.id === 0 ? null : item.id
}));
}

return transformData(data);

It is such a small thing but really stops the data id logging correctly.

2 Likes

Thank you for the help and advise I have taken your advice and solved. in my second instance issue was on mysql side.. Appreicate it.

2 Likes

Glad to help. And welcome to the forums!