Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form fields to JSON #1866

Open
Oviglo opened this issue Feb 12, 2018 · 3 comments
Open

Form fields to JSON #1866

Oviglo opened this issue Feb 12, 2018 · 3 comments

Comments

@Oviglo
Copy link

Oviglo commented Feb 12, 2018

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

@hpatoio
Copy link
Contributor

hpatoio commented Mar 22, 2018

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

@Oviglo
Copy link
Author

Oviglo commented Mar 22, 2018

Thank you, I installed this bundle but what is the best pratice to use this automaticaly with FOSRest ? I need to override JsonViewHandler ?

@hpatoio
Copy link
Contributor

hpatoio commented Mar 22, 2018

I need to override JsonViewHandler ?

That's an option. Otherwise you can register a ViewResponseListener and handle it there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants