Make WordPress Core

Ticket #28053: media-modal.28053.diff

File media-modal.28053.diff, 4.1 KB (added by LindsayBSC, 9 years ago)

media-views.js and attachment-compat.js patch for multiple value input as javascript array object patch

  • src/wp-includes/js/media-views.js

    diff --git src/wp-includes/js/media-views.js src/wp-includes/js/media-views.js
    index 0f53b0a..f7fada8 100644
    AttachmentCompat = View.extend({ 
    23512351                }
    23522352
    23532353                _.each( this.$el.serializeArray(), function( pair ) {
    2354                         data[ pair.name ] = pair.value;
     2354                        /*
     2355                         * Begin patch for dealing with multiple value input fields
     2356                         */
     2357                         
     2358                         // if the pair.name is greater than 2 chars and [] is the last two chars
     2359                         if ( pair.name.length > 2 && '[]' == pair.name.substr( pair.name.length - 2 ) ) {
     2360                         
     2361                                                                        // defined item as the name minus the []
     2362                                                    var item = pair.name.substr( 0, pair.name.length - 2 );
     2363                                                        //if item wasn't passed previously in data
     2364                                                     if ( item in data ) {
     2365                                                                  // combine all of the pair.value together to one data[item] comma separated
     2366                                                              var list =  data[ item ] += ',' + pair.value;
     2367                                                             
     2368                                                              // split the list into a javascript object
     2369                                                              data[ item ] = list.split(',');
     2370                                                             
     2371                                                         
     2372                                                     /* if it is the first time sending for 'item' just add once   
     2373                                                      * storing even single records as an array only for inputs that have name="somename[]"
     2374                                                      */
     2375                                                          } else {
     2376                                                                var list = pair.value;
     2377                                                                data[ item ] = list.split(',');
     2378                                                          } // end  if ( item in data )
     2379                                     
     2380                                     //else if name does not end in []                     
     2381                                    } else {
     2382                                         // send the value only
     2383                                         data[ pair.name ] = pair.value;
     2384                                   }
    23552385                });
    23562386
    23572387                this.controller.trigger( 'attachment:compat:waiting', ['waiting'] );
  • src/wp-includes/js/media/views/attachment-compat.js

    diff --git src/wp-includes/js/media/views/attachment-compat.js src/wp-includes/js/media/views/attachment-compat.js
    index a54c224..803c3fa 100644
    AttachmentCompat = View.extend({ 
    6868                }
    6969
    7070                _.each( this.$el.serializeArray(), function( pair ) {
    71                         data[ pair.name ] = pair.value;
     71                        /*
     72                         * Begin patch for dealing with multiple value input fields
     73                         */
     74                         
     75                         // if the pair.name is greater than 2 chars and [] is the last two chars
     76                         if ( pair.name.length > 2 && '[]' == pair.name.substr( pair.name.length - 2 ) ) {
     77                         
     78                                                                        // defined item as the name minus the []
     79                                                    var item = pair.name.substr( 0, pair.name.length - 2 );
     80                                                        //if item wasn't passed previously in data
     81                                                     if ( item in data ) {
     82                                                                  // combine all of the pair.value together to one data[item] comma separated
     83                                                              var list =  data[ item ] += ',' + pair.value;
     84                                                             
     85                                                              // split the list into a javascript object
     86                                                              data[ item ] = list.split(',');
     87                                                             
     88                                                         
     89                                                     /* if it is the first time sending for 'item' just add once   
     90                                                      * storing even single records as an array only for inputs that have name="somename[]"
     91                                                      */
     92                                                          } else {
     93                                                                var list = pair.value;
     94                                                                data[ item ] = list.split(',');
     95                                                          } // end  if ( item in data )
     96                                     
     97                                     //else if name does not end in []                     
     98                                    } else {
     99                                         // send the value only
     100                                         data[ pair.name ] = pair.value;
     101                                   }
     102                                   
    72103                });
    73104
    74105                this.controller.trigger( 'attachment:compat:waiting', ['waiting'] );