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

Multiple select #37

Closed
Blixia opened this issue Oct 8, 2014 · 2 comments
Closed

Multiple select #37

Blixia opened this issue Oct 8, 2014 · 2 comments

Comments

@Blixia
Copy link

Blixia commented Oct 8, 2014

I had a 'multiple' attribute in my select element and only the last selected value would get passed along.

Basically I edited one function and added another. To me it seems 'dirty'.

function getMultiple(pairs,multiName,current)
{
  var multipleValues = [];
  for (var i = current; i<pairs.length; i++)
  {
    if(pairs[i].name === multiName)
        multipleValues.push(pairs[i].value);
    else
        break;
  };
    var obj = makeObject(multiName, encode({name:multiName,value: multipleValues}));
    data = helper.extend(true, data, obj);
    return i;
}

function addPairs(pairs) {
  if (!helper.isArray(pairs)) {
    throw new Error("formSerializer.addPairs expects an Array");
  }
  for (var i=0, len=pairs.length; i<len; i++) 
  {
    if($('[name="'+pairs[i].name+'"]').attr('multiple') )
    {
        i = this.getMultiple(pairs,pairs[i].name,i);
    }
    else
        this.addPair(pairs[i]);
  }
  return this;
}

Also added the following to the public API:

this.getMultiple = getMultiple;

I have NOT tested anything beside that I get a object with named key and an 'array' as value IE:

Object{
name : array[x]
0 : 'value',
1 : 'value',
2 : 'value',
}
etc

I wonder if multiple select is going to be supported?

@macek
Copy link
Owner

macek commented Oct 8, 2014

Using the 2.x version of the plugin,<select name="foo[]" multiple> works fine, you just have to use the proper name attribute with the [] operator on it.

I am currently working on 3.x which will fully implement W3C HTML JSON form submission spec as discussed in #24.

Using 3.x you will be able to do <select name="foo" multiple> and get an array of results.

If you have any other questions, let me know.

@Blixia
Copy link
Author

Blixia commented Oct 8, 2014

Great!

That answers everything for me.

@macek macek closed this as completed Oct 8, 2014
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