validform整合swfupload

引用js  Validform.swfupload.handler-min.js与swfuploadv2.2-min.js

 

页面初始化

$(function(){
    $("#frm").Validform({
    tiptype:2,
    datatype:{
        "qzh":/^[\w_]{1,30}$/,
        //"chi":/^[\w\d_!]{1,30}$/,
        "s1-s16": /^[\w\u4e00-\u9fa5_]{1,16}$/,
         "s1-s60":/^[\w\W]{1,60}$/,
          "datacheck":function(gets,obj,curform,regxp){
              if(obj.id=="filestart"){
                return ($("#fileend").val()==""&&gets=="")||($("#fileend").val()!=""&&gets!="");
            }else{
                return (gets==""&&$("#filestart").val()=="")||(gets!=""&&$("#filestart").val()!="")&&(gets>=$("#filestart").val());
            }
         }
    },
    usePlugin:{
            swfupload:{
                file_post_name: "myFile",
                file_size_limit : "1024",    // 100MB
                file_types : "*.doc;*.pdf;*.docx;*.xls;*.xlsx,*.ppt",
                file_types_description : "All Files",
                file_upload_limit : "1",
                file_queue_limit : "0",
                upload_url: "<%=request.getContextPath()%>/generalManager/saveFile.action",
              button_image_url : "<%=basePath%>image/XPButtonUploadText_61x22.png",
                button_placeholder_id : "spanButtonPlaceholder1",    
            flash_url : "<%=basePath%>js/upload/swfupload.swf",
                
                //覆盖默认绑定好的事件;
                file_dialog_complete_handler:function(){
                    //reset the default event;
                },
                upload_complete_handler:function(){
                    //文件上传完成后触发表单提交事件,通过this.customSettings.form可取得当前表单对象;
                    this.customSettings.form.get(0).submit();

                }
            }
        }
        
        ,
        callback:function(){
            //可用通过 swfuploadhandler.SWFUPLOAD_demo2_0 获取到当前表单下的swfupload对象;
            //swfuploadhandler是默认的事件对象,里面预设好了swfupload对象各事件触发时的动作函数;
            //SWFUPLOAD_[demo2]_[0] => SWFUPLOAD_[该表单的ID]_[该表单在Validform初始化时的索引值];
            if($(swfuploadhandler.SWFUPLOAD_frm_0).find("[plugin*='swfupload']").val()===""){
                swfuploadhandler.SWFUPLOAD_frm_0.customSettings.form.get(0).submit();
            };
            //针对非ajax表单提交方式,可以在这里触发上传事件,这样可以实现表单验证全部通过才上传文件;
            swfuploadhandler.SWFUPLOAD_frm_0.startUpload();
            
            //return false;
        }
            
        
    
    });
});

jsp页面

 <input type="text" name="myFile" id="file" plugin="swfupload"  disabled="disabled" /><span id="spanButtonPlaceholder1"></span>
              <input type="hidden" pluginhidden="swfupload" name="hidFileID" id="hidFileID" value="" />
              
      

 

 

设置完成后,会先提交文件,再次提交表单。

测试通过,记一下代码用以备忘。

posted on 2013-01-25 16:05  T.W.M  阅读(459)  评论(0编辑  收藏  举报

导航