Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

FileAPI doesn't format js-objects correctly #121

Closed
warappa opened this Issue · 4 comments

2 participants

David Rettenbacher Lebedev Konstantin
David Rettenbacher

I have a js-object like this:

{
    name: "asdf",
    items: [{
        itemName: "a"
    },
    {
        itemName: "b"
    }]
}

In the POST an item is encoded as items[0][itemName]. Asp .NET model binder doesn't like that (is it even standard conform?). What it likes is items[0].itemName.

So I created a patch which fixes the issue.

DISCLAMER: I'm new to git.

As I can't attach the patch, here is it:

diff --git a/lib/FileAPI.core.js b/lib/FileAPI.core.js
index 175076b..2d94568 100644
--- a/lib/FileAPI.core.js
+++ b/lib/FileAPI.core.js
@@ -1047,11 +1047,17 @@

                // Append data
                _each(options.data, function add(val, name){
-                   if( typeof val == 'object' ){
+                   var isArray = Object.prototype.toString.call(val) === "[object Array]";
+                   if( isArray == true ){
                        _each(val, function (v, i){
                            add(v, name+'['+i+']');
                        });
                    }
+                   else if( typeof val == 'object' ){
+                       _each(val, function (v, i){
+                           add(v, name + '.' + i);
+                       });
+                   }
                    else {
                        Form.append(name, val);
                    }
Lebedev Konstantin
Owner

I understood you.
But it is better to do so:

// .NET
var FileAPI = {
    postNameConcat: function (name, idx){
          if( idx != null ){
               name += (idx >= 0 ?  '['+ idx +']' : '.' + idx);
          }
          return name;
    }
};


// Default
var FileAPI = {
    postNameConcat: function (name, idx){
          if( idx != null ){
               name += '['+ idx +']';
          }
          return name;
    }
};
David Rettenbacher

Did you mean this should be already supported? If yes, which version is required because I'm using 1.2.4 and tried 1.2.6 but both don't pick up postNameConcat.

Lebedev Konstantin
Owner

Alas, no, but in the evening certainly will do.

Lebedev Konstantin
Owner

Done.

Lebedev Konstantin RubaXa closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.