Comments (9)
yeh, that's a problem of jQuery on input returning only one value for the select list , even if multiple is enabled.
jsonform would have to find all the select w multiple(special classname), and get the values (.val())
for each and add it to the returned form inputs
something like this
https://www.techiedelight.com/get-selected-values-multi-select-drop-down-list-jquery/
from jsonform.
Couldn't you inspect metadata on the schema/form element to identify those items that needed alternate processing? Can you help me to understand why you would need to look for a special class name?
from jsonform.
well, we need to get the data from the form
the code does
var formArray = $(':input', this.el).serializeArray();] // line 2572
which gets all the non-empty input fields with names
and it got the select/last checked
and then it gets all the unchecked checkboxes
formArray = formArray.concat( // line 2576
now we need to find all the places we COULD get more data so
select with multiple attribute set...
and we need to resolve the one field returned vs all/only fields
but that gets us the data, not where it goes in the schema..
there is a bunch of code following this that tries to locate the place in the schema..
I haven't gone thru that myself yet. but if we had the select element classname, we could match.
and we HAVE the element to get the values..
from jsonform.
in the short term, you could try the multiple checkboxes approach I submitted as a PR
from jsonform.
well, after a little investigation.. when the submit is fired we DO get all the values. so, its the code loading them into the result..
of course it doesn't see 'multiple' yet ... so uses the last one in the list
from jsonform.
Thanks for the pointer! I did some digging and was able to find what you mentioned, that the values are all coming back, but as individual objects in the array. Since the select is defined as a "string", whichever item is last in wins and is what is returned. I spent some time debugging and was able to add the following to get all the items to process:
var formEl = $("[name='" + name + "']")[0];
if(formEl && formEl.tagName == 'SELECT' && formEl.multiple == true) {
cval = jsonform.util.getObjKey(values, name) || [];
enumIndex = eltSchema['enum'].indexOf(formArray[i].value);
cval.push(eltSchema['enum'][enumIndex]);
jsonform.util.setObjKey(values, name, cval);
continue;
}
Once these process, the issue becomes that the elements fail validation as the select is defined as a string and not an array. It feels like there should be a "select" form type similar to checkboxes and radios. If I disable validation, I am able to retrieve the results as expected. I am going to keep digging, but would welcome feedback on how to transition a select field to support arrays so that validation could be enabled.
It may make sense as part of a larger refactoring to iterate through the identified form elements and not the serialized form so that decisions and processing could be done on an input by input basis. Just a thought.
from jsonform.
there is a special flag for arrays of checkboxes
_jsonform_checkboxes_as_array
but the select submit data doesnt work there..
will look a little more. I had validation turned off to be able pass a file object back to the form user to handle uploaded file
from jsonform.
your code above, yeh, see what happens after input.
each data type is checked, cause the 'form' returned string, work has to be done for number, integer and boolean for sure. hate to dup code...
from jsonform.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from jsonform.
Related Issues (20)
- Add custom field to fieldset HOT 2
- activeClass isn't applied correctly for schemas with defaults HOT 2
- How to build a stepper form HOT 4
- process change, just fyi.. all PRs against develop branch
- Expanded Fieldset + Default TabIndex set - Collapse issue (bug) HOT 4
- tabs-left not supported in bootstrap v3
- Hide submit button HOT 2
- How to escape slash in scope HOT 3
- Rendering fails if property name contains dots HOT 1
- Missing array brackets [] on array items when using a custom field type HOT 1
- Error: JSONForm does not yet support schemas that use the $ref keyword. See: #54" HOT 2
- Boolean options are always true HOT 5
- How to use this library with bundler HOT 1
- How to show error after a control value is changed, HOT 1
- date / datetime formatting HOT 3
- Advancedfieldset form folding click handle gets duplicated when jsonform gets called again causing the folded form to flick HOT 6
- Textarea Rows HOT 2
- Fieldset along with the Select all checkbox. HOT 7
- Array binding issue HOT 7
- Swapping the images HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonform.