tobimori / kirby-dreamform

✨ DreamForm is an opiniated form builder plugin for Kirby CMS that makes forms work like magic
https://plugins.andkindness.com/dreamform
44 stars 7 forks source link

Select fields do not retain their values on page reload when form does not validate #46

Closed animaux closed 6 months ago

animaux commented 6 months ago

When trying to submit a form that does not validate, the page gets reloaded showing an error message. If I have selected an option from a select-field before submitting, my choice gets lost and I have to select the desired option again.

The expected result would be for the option to be remembered and kept until the form is successfully submitted.

As a sidenote: is there a special reason why the required-attribute is not inserted in required fields? This would add an extra-validation layer before submission and is supported by virtually all modern browsers.

tobimori commented 6 months ago

The required attribute is added to fields that must be filled out. However, browsers will ignore this attribute since the form has the novalidate attribute set. The reason for using novalidate is that the built-in browser validation is not easily customizable without JavaScript, and we have extensive custom server-side validation checks in place.

In my opinion, this can lead to a poor user experience as form would display two different types of error messages: one from the browser's native validation and another from the server-side validation.

The Email field serves as a good example to illustrate the differences between browser and server-side validation:

Validation Check Browser Server
Field is required
Value is a valid email format
Email domain actually exists
Email domain is not a throwaway/spam email

As you can see, the browser validation stops way early. This pattern is similar for all other form fields.

tobimori commented 6 months ago

I fixed the bug you mentioned and it will be included in the upcoming release in the following days.

animaux commented 6 months ago

Thanks for elaborating on the required-attribute, sounds very reasonable!