CodeForPhilly / stately

Form-driven workflow engine
http://tinyurl.com/statelydeck
21 stars 5 forks source link

Feature: Form designer #28

Open timwis opened 7 years ago

timwis commented 7 years ago

Using this issue to jot down ideas about the form designer. We could try to reuse dobt's form designer ... but if we didn't....

We could use dragula and HTML5's contenteditable, and simply serialize the DOM.

So there'd be a form area, and a way to add fields to it. Adding an <input type="text"> would actually add a <div class="draggable"><label><input><p class="description"></div>. The <div> would have dragula enabled on it. Dragging it around simply rearranges it in the DOM. The <label> and description <p> would have contenteditable="true", letting the user directly edit their contents (which also just updates the DOM).

"Saving" the form would be a matter of exporting formArea.innerHTML. Sure, we could serialize it into JSON if we want to, but there may be an advantage to simply storing the HTML. For instance, you could very easily customize it to infinity. We'd just need a way to associate the fields with the data, but that shouldn't be too hard; just require that each field has a <label> and use an underscorified_version_of_the_label as the field name.

Sounds like fun!

timwis commented 7 years ago

Proof of concept: http://craven-relation.surge.sh/

I don't think this would work as well for <select> boxes ... there'd have to be some kind of configuration panel.