[jQuery] Re: Interacting with the MultiFile Plugin

2007-09-17 Thread Rob Wilkerson


On Sep 17, 9:17 am, Rob Wilkerson [EMAIL PROTECTED] wrote:
 I have a form that is using both the ajaxFileUpload and the MultiFile
 plugins.  When a user selects a file for upload, the change event
 uploads the file via ajax for validation.  If an error occurs, I need
 to remove the file from the MultiFile queue.  I can (and have)
 manually removed the elements, but that doesn't decrement the maxfile
 counter, of course.

 The easy way to do all of this is to trigger the MultiFile function
 that is called when the user deletes the file from the UI, but I can't
 figure out how to do that or, for that matter, if it's even possible.

 Here is a snippet from within my $.ajaxFileUpload() where I'm manually
 removing the UI components:

 success: function ( data, status ) {
 try {
 var index = /\d+$/.test ( input.name ) ? input.name.replace ( 
 /^.+
 (\d)+$/, '$1' ) : 0;
 /**
  * If there's an error in the upload process, remove the 
 relevant
  * UI elements.
  */
 if ( data['error'].length  0 ) {
 $('#multi_0_' + index ).remove();
 $('a[href^=#multimulti_]:last').parent().remove();
 /** TODO: have to decrement the counter within the 
 MultiFile
 object...how? */

 throw ( data['error'] );
 }
 else {
 // Debug
 // alert ( data['files'] );
 $('form').prepend (
 'input type=hidden ' +
 'id=uploaded' + index + ' ' +
 'name=uploaded' + index + ' ' +
 'value=' + encodeURI ( data['files'] ) + ' 
 ' +
 '/'
 );
 }
 }
 catch ( e ) {
 alert ( 'Error: ' + e.message );
 }

 },


Oh, to see the forest through the trees.  It seems to work if I
manually trigger the click event of the link.  sigh

$('a[href^=#multimulti_]:last').trigger ( 'click' );



[jQuery] Re: Interacting with the MultiFile Plugin

2007-09-17 Thread Rob Wilkerson


On Sep 17, 9:17 am, Rob Wilkerson [EMAIL PROTECTED] wrote:
 I have a form that is using both the ajaxFileUpload and the MultiFile
 plugins.  When a user selects a file for upload, the change event
 uploads the file via ajax for validation.  If an error occurs, I need
 to remove the file from the MultiFile queue.  I can (and have)
 manually removed the elements, but that doesn't decrement the maxfile
 counter, of course.

 The easy way to do all of this is to trigger the MultiFile function
 that is called when the user deletes the file from the UI, but I can't
 figure out how to do that or, for that matter, if it's even possible.

 Here is a snippet from within my $.ajaxFileUpload() where I'm manually
 removing the UI components:

 success: function ( data, status ) {
 try {
 var index = /\d+$/.test ( input.name ) ? input.name.replace ( 
 /^.+
 (\d)+$/, '$1' ) : 0;
 /**
  * If there's an error in the upload process, remove the 
 relevant
  * UI elements.
  */
 if ( data['error'].length  0 ) {
 $('#multi_0_' + index ).remove();
 $('a[href^=#multimulti_]:last').parent().remove();
 /** TODO: have to decrement the counter within the 
 MultiFile
 object...how? */

 throw ( data['error'] );
 }
 else {
 // Debug
 // alert ( data['files'] );
 $('form').prepend (
 'input type=hidden ' +
 'id=uploaded' + index + ' ' +
 'name=uploaded' + index + ' ' +
 'value=' + encodeURI ( data['files'] ) + ' 
 ' +
 '/'
 );
 }
 }
 catch ( e ) {
 alert ( 'Error: ' + e.message );
 }

 },


Oh, to see the forest through the trees.  It seems to work if I
manually trigger the click event of the link.  sigh

$('a[href^=#multimulti_]:last').trigger ( 'click' );