Make WordPress Core

Ticket #28053: media-modal.28053.2.diff

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

[fixed tabs] 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..5196fea 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                                                                       
     2366                                                                        // combine all of the pair.value together to one data[item] comma separated
     2367                                                                        var list =  data[ item ] += ',' + pair.value;
     2368                                                                       
     2369                                                                        // split the list into a javascript object
     2370                                                                        data[ item ] = list.split(',');
     2371                                                       
     2372                                                       
     2373                                                        /* if it is the first time sending for 'item' just add once   
     2374                                                         * storing even single records as an array only for inputs
     2375                                                         * that have name="somename[]"
     2376                                                         */
     2377                                                        } else {
     2378                                                                var list = pair.value;
     2379                                                                data[ item ] = list.split(',');
     2380                                                        } // end  if ( item in data )
     2381                               
     2382                                //else if name does not end in []                     
     2383                                } else {
     2384                                // send the value only
     2385                                data[ pair.name ] = pair.value;
     2386                                }
    23552387                });
    23562388
    23572389                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..8dd48f4 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                                                               
     83                                                                // combine all of the pair.value together to one data[item] comma separated
     84                                                                var list =  data[ item ] += ',' + pair.value;
     85                                                               
     86                                                                // split the list into a javascript object
     87                                                                data[ item ] = list.split(',');
     88                                               
     89                                               
     90                                                /* if it is the first time sending for 'item' just add once   
     91                                                 * storing even single records as an array only for inputs
     92                                                 * that have name="somename[]"
     93                                                 */
     94                                                } else {
     95                                                        var list = pair.value;
     96                                                        data[ item ] = list.split(',');
     97                                                } // end  if ( item in data )
     98                       
     99                        //else if name does not end in []                     
     100                        } else {
     101                        // send the value only
     102                        data[ pair.name ] = pair.value;
     103                        }
    72104                });
    73105
    74106                this.controller.trigger( 'attachment:compat:waiting', ['waiting'] );