brutusin / json-forms

JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
http://brutusin.org/json-forms
Apache License 2.0
607 stars 168 forks source link

Add multi-select functionality #71

Closed tejovanthn closed 7 years ago

tejovanthn commented 7 years ago

In the enum fields, I thought we could use a field like multiple = true to make the select field into a multi-select checkbox.

The change will need to include

if (s.multiple){
    input.multiple = true;
}

while handling the s.enum case in renderers["string"]

And

 if (schema.enum) {
     if(input.multiple){
         value = Array.from(input.options).reduce(function(acc, el){
                 if(el.selected){acc.push(el.textContent);}
                 return acc;
                 },[]).join(",");
     }   
     else{
         value = input.options[input.selectedIndex].value;
     }   
 }

while handling getValue to save the selected values (hacky).

idelvall commented 7 years ago

Hi, @tejovanthn . Given that this is not a standard feature, i can't integrate it into the main code, nevertheless, you can extend the library to support it without needing to integrate it into the code, by adding a custom decorator.

For custom decorator examples see :