Replies: 2 comments 6 replies
-
It feels like your thinking is a bit more complicated than it needs to be.
This is not true. You will give yourself a lot more trouble if you try to validate all inputs all the time. In the end when it comes to data submission, only backend validation matters. Frontend validation is only something nice for the user that you can perform sporadically.
I don't understand your usage of the word
Given the way HTML forms work, thinking about form submission with multiple forms on the same page doesn't make a lot of sense, since only one form should be submitted at the time. If you have many forms you want to validate and submit at the same time, it might be that you are thinking about form submission in a wrong way. Keep in mind doing any kind of validation in the frontend (i.e. Javascript) is not secure as anyone could bypass it. It should just be viewed as a nice UX bonus, nothing more. PS: You might want to take a look at this community add-on dedicated to form state management with VanJS. |
Beta Was this translation helpful? Give feedback.
-
Not sure what you meant by this. Do you have a concrete example where things are running into troubles? |
Beta Was this translation helpful? Give feedback.
-
I am still struggling with web development and I would like to discuss the following observation.
Imagine a web application, which is a sequence of forms each containing a sequence of input fields. The DOM might look like this:
Every input should be validated, every form should be validated and all forms should be validated. Because the input has an impact on the validation, both are states. When I put each state in a variable, which lives in an environment of a procedure, each validity can only be defined after the corresponding input, because the validity depends on the input, the same for the combined validities. In the end the definitions will have the following order:
This is exactly the opposite order of the DOM tree.
VanJS advocates two aspects:
But the shape of the procedures building the DOM tree is contrary to the shape of the procedures working on the states. How does this fit together?
The alternative would be to store the states right in the DOM tree. Every element, which needs validation, can store the validation state in its dataset. And when a validity of an input element has changed the element can emit a bubbling custom event. It will bubble the DOM tree up and every element on its way can react to the event by updating its validation state. This works right out of the box without any help of a toolkit. Is seems to me that for this particular use-case a DIY solution is much easier than a solution using VanJS.
Beta Was this translation helpful? Give feedback.
All reactions