Skip to content

Instantly share code, notes, and snippets.

@LinzardMac
Created August 17, 2015 15:49
Show Gist options
  • Save LinzardMac/e8b6bcc9d3a59c60322d to your computer and use it in GitHub Desktop.
Save LinzardMac/e8b6bcc9d3a59c60322d to your computer and use it in GitHub Desktop.
_.each( this.$el.serializeArray(), function( pair ) {
/*
* Feature Added: returns js array object for multiple value inputs
* This is the reason we had to override the default save function
* function originates in media-views.js line 2295
*/
// if the pair.name is greater than 2 chars and [] is the last two chars
if ( pair.name.length > 2 && '[]' == pair.name.substr( pair.name.length - 2 ) ) {
// defined item as the name minus the []
var item = pair.name.substr( 0, pair.name.length - 2 );
//if item wasn't passed previously in data
if ( item in data ) {
// combine all of the pair.value together to one data[item] comma separated
var list = data[ item ] += ',' + pair.value;
// split the list into a javascript object
data[ item ] = list.split(',');
/* if it is the first time sending for 'item' just add once
* storing even single records as an array only for inputs that have name="somename[]"
*/
} else {
var list = pair.value;
data[ item ] = list.split(',');
} // end if ( item in data )
} else { // end if name ends in []
// send the value only
data[ pair.name ] = pair.value;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment