kevinchappell / formBuilder

A jQuery plugin for drag and drop form creation
https://formbuilder.online
MIT License
2.6k stars 1.38k forks source link

How to custom multiple input in one field and set the JSON output is array or object? #1583

Closed ShingYYY closed 1 month ago

ShingYYY commented 1 month ago

How to custom multiple input in one field and set JSON output is array or object?

seem like this: image

And then JSON output Can be array: { "answers": [ "A", "B", "C" ] }

Can be object: { "answers": { "answer_1": "A", "answer_2": "B", "answer_3": "C" } }

In addition, I am very grateful to the developer who created formBuilder. It helped me solve 70% of the problems. Thank you.

lucasnetau commented 1 month ago

You'll need to make a plugin that creates multiple input[type=text] or textarea's with the name set with a [] at the end in the build stage. formBuilder will save the results as an array out of the box ["A","B","C"]

To do your object return you should look at creating an extra hidden input with your name and then don't set a name on the text inputs. Then have a change handler set to update the hidden input with the json encoded object. formBuilder will then pickup the hidden input only. ["{...}"]

ShingYYY commented 1 month ago

Thank you for your advice. It inspires me a lot.