FOSRestBundle
FOSRestBundle copied to clipboard
Form fields to JSON
Hi, I want to send form fields informations (attributes etc.) allow to generate this form with vue.js
When I send form to the view I have only the fields names:
{"username":[],"email":[],"actions":{"save":[],"cancel":[]}}
I would like:
{"username":{"type":"text", "label": "Username", "attr" : {"maxlength": 100}},...
Can you tell me how ? Thanks
I've created a json schema handler that use this bundle: https://github.com/Limenius/LiformBundle Responses are like:
{
"title": "form",
"type": "object",
"properties": {
"birthdate": {
"type": "string",
"title": "birthdate",
"widget": "date",
"propertyOrder": 1
},
"email": {
"type": "string",
"title": "email",
"widget": "email",
"format": "email",
"propertyOrder": 2
},
"firstname": {
"type": "string",
"title": "firstname",
"propertyOrder": 3
},
"lastname": {
"type": "string",
"title": "Last name",
"propertyOrder": 4
}
},
"required": [
"birthdate",
"email",
"firstname",
"lastname"
]
}
These are json schema, so you can also use it to validate data client side before send them. See this post for details https://blog.apisyouwonthate.com/the-many-amazing-uses-of-json-schema-client-side-validation-c78a11fbde45
Thank you, I installed this bundle but what is the best pratice to use this automaticaly with FOSRest ? I need to override JsonViewHandler ?
I need to override JsonViewHandler ?
That's an option. Otherwise you can register a ViewResponseListener and handle it there