Hi,
I'm facing a similar issue to the above linked. I resolved a case where I was using Key value pairs for adding a record, but am now looking at another form where I was using Insert a record using Object - {{newAccountForm.data}}
There are four optional date fields on the form. So I could switch over to using Key value pairs but would like to know if there's a simpler solution than setting up each form element and adding in the logic to convert '' to null?
You are passing in the form's .data property to a query instead of my field-by-field version?
In that case you can use this one-liner in your query's Changeset Object property (thank you ChatGPT) to convert all empty strings to null (not tested!)
And I'm filtering by {{ editPK.value }} which is a hidden field on the form (in a modal).
updateAccForm failed (0.202s):Empty .update() call detected! Update data does not contain any values to update. This will result in a faulty query. Table: hosting_accounts. Columns: {{editAccForm..data.fromEntries(Object.entries(jsonObj).map(([k, v]) => [k, v === "" ? null : v]))}.
error:"Unprocessable Entity"
message:"Empty .update() call detected! Update data does not contain any values to update. This will result in a faulty query. Table: hosting_accounts. Columns: {{editAccForm.data.fromEntries(Object.entries(jsonObj).map(([k, v]) => [k, v === "" ? null : v]))}."
data:null
Instead of inserting a null you could try omitting the "empty" properties?
something like this maybe but perhaps more logic on what you consider "empty" to be: _.omitBy(editAccForm.data, x => {return !!!x})
The code is not green (you can see it is green in the filter by value above it) . No green no good! There is an error in the code.
You can also place your cursor into the entry box and it will also show you the return value of the code. Yu can use this to determine if the code it working right:
I think you are exactly right that there should be a checkbox allowing us to choose between saving '' and saving NULL.
I suspect it is empty string because the component was designed prior to the release of the retool database. I am happy to be wrong as I haven't tested on different data sources.
Either way, perhaps @Tess will look at this. With the advent of retool_db I think such a feature would bring the date component in line with using NULLs in SQL.
Personally I'd file it under bugs because the advertised behaviour of the component is not the same for the different backends.