Replies: 3 comments 4 replies
-
What is the comportment for a textfield in a form that have a listener defined ? Is the textfield content also part of the form data or not ? |
Beta Was this translation helpful? Give feedback.
2 replies
-
After discussion, this is what we choose :
With this form : {
"type": "form",
"onSubmit": {
"action": "registerNewsletter",
"props": {"from": "homePage"}
}
"children": [{
"type": "checkbox",
"value": false,
"name": "acceptEmail"
}, {
"type": "textfield",
"value": "[email protected]",
"name": "email"
}, {
"type": "button",
"submit": true,
"text": "OK"
}]
} The onSubmit event looks like this : { "value": {"acceptEmail": false, "email": "[email protected]"}} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The problem
To add a form in a lenra app, we curenly have no other way than storing all the input current value into a data every time we receive a change event.
Then when the button is clicked, retreive this data and create our "real" new data.
This is highly annoying and should be simplified.
One possible solution
To fix this issue, we could add a
Form
component. This form could be linked to multiple inputs and a validation button.When the validation button is pressed, a form event is sent to a listener which include the value of all linked input.
Simple and efficient.
Could send the event data :
Client side form validation
Using this form, we could add some constraints to each inputs. When the form is validated (or dynamically when the user change the field) we could validate the input and print an error if needed.
Server side form validation
Since this form validation is never enough to ensure security, the validations should also be checked server side.
Since all the necessary informations are already present in the json, we could also validate the event sent to the server using these data. For example, if
event.form.isValid == true
then the dev can trust the values in the form and add them to the stored data.Beta Was this translation helpful? Give feedback.
All reactions