kompassi icon indicating copy to clipboard operation
kompassi copied to clipboard

In addition to `process_form_data`, should we have its reverse `values_to_form_data`?

Open japsu opened this issue 1 year ago • 0 comments

The idea of form_data vs. values is to store whatever the user's browser sent in form_data and only convert it on demand to values. form_data is always* dict[str, str] whereas values can be dict[str, str | int | list[str] | dict[str, str]] or even more types.

Currently SchemaFormInput is responsible for understanding the values type of its value (eg. DateTimeField: ISO 8601 string #438, NumberField: number etc.) and making whatever conversion is required to enable an <input> to display it.

Should this conversion be pushed to the backend, or should we expose the raw Response.form_data so that field implementation would be more straightforward <input type={type} value={value}>?

The form_data -> values -> form_data conversion cycle may still be preferred in order to perform satanization.

*) Actually not true due to FileUploadField value in form_data always being list[str] regardless of number of files. So we are already touching the form_data in frontend before it reaches the databae.

japsu avatar Feb 19 '24 07:02 japsu