We implemented this in some of the previous beta versions.
Seems like some of the more advanced field types confuse a lot of new/inexperienced users, so we only show the most basic ones in the Basic mode.
Yes, i appreciate that but i have done this literally hundreds of items and never had to do that. Is there a reason? Am i going to have to add a default to every numeric field in future or more worrying add them to existing sites if I update them?
The form submits an empty string, in the database you have a default set and allow null. What exactly do you expect that it inserts? The default that is set in the database is used when the value was not supplied with the insert or when the DEFAULT keyword is used. When the value is null then null will be inserted in the database. Empty string is not valid for the decimal field, but would be a valid value for a text field. Should it then insert an empty string when there is also a default set in the database? We can’t know this and require you to tell the app what it should do.
I think there is some confusion here @patrick.
When the form is submitted with a numeric field left blank I expect it to either insert Null or the database default depending on the settings which is what has always happened in the past. Now if I I leave numeric form field blank I get an error message. I would never expect an empty string, this thread is about decimal fields
Brian,
An empty form input always sends an empty string on submit. It's always been like that.
Check what the HTML spec defines: HTML Standard
The value attribute, if specified and not empty, must have a value that is a valid floating-point number. The value sanitization algorithm is as follows: If the value of the element is not a valid floating-point number, then set it to the empty string instead.
So what you are saying is that if you have a form input of the type Number and that field is left blank then a database update server action will return an error unless a default is set in the data base update query?
All i want is for there to be no error if a number field in a form is left empty. I could do that until recently. Tomorrow i will make a video to show you exactly what my issue is but at the moment a bottle of red wine takes priority
Hi Brian,
We understand what your issue is and Patrick already explained how and why it works like that.
The server action receives an empty string from the form and we don't know what do you (or other users) want to do with it - if you want null to be inserted then use the default formatter with a null value.
It's your database which returns an error because it's not allowed to insert empty strings in decimal field type in MySQL.
So yes, you need to use the default formatter if you expect empty strings to be sent to such fields and that's why this formatter exists.
Maybe you want to use the condition option in your insert step for these form fields so their values are only sent to the db when a value is actually entered.
This way the default set in your DB settings will be used on insert.
We found out that the database was in strict mode, that’s why it throws an error on an empty string. When the database is not in strict mode it would convert and empty string to 0 and no error will occur. So fact is that the database handles values different depending on which mode it is running in.