0

当重新加载表单时bootstrapvalidator不起作用。当我第一次提交表单时,它可以正常工作,但是当单击添加更多记录时,它无法正常工作。

HTML 表单是...

<form class="clearfix"  role="form" class="form-horizontal" id="upload-resume-form" method="post" enctype="multipart/form-data">
 <div class="col-sm-7 col-md-7  mar-bot-min2">
     <input type="text" class="form-control" placeholder="Resume Title" name="name"/>
  </div>
  <div class="col-sm-7 col-md-7  mar-bot-min2">
      <input type="text" class="form-control" placeholder="Upload resume" id="resume_name"  / >
   </div>
   <div class="col-sm-4 col-md-4  mar-bot-min2">
       <a class="btn _btn  blu-blu-lg browse-btm">Choose File</a>
                            <div class="hid-brow-btn">
                                <input type="file" name="resume_file" id="resume_file" />       
                            </div>
                        </div>
      <div class="col-xs-12 col-sm-12 col-md-12 mar-bot-min2 buttongroup">
      <button type="button" class="btn _btn gr-drk" data-bind="click:uploadResume"><i class="fa fa-save fa-fw"></i>Save</button>
       <button type="button" class="btn _btn gr-drk " data-bind="click: cancelResume"><i class="fa fa-ban fa-fw"></i>Cancel</button>
    </div>
</form>

JS代码

$(document).ready(function(){
 $('#upload-resume-form').bootstrapValidator({
  feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
       name: {
            validators: {
                notEmpty: {
                    message: 'Resume title is required'
                },
                regexp: {
                regexp: /^[A-Za-z\s.'-]+$/,
                message: "Alphabetical characters, hyphens and spaces"
            }
            }
        },

        resume_file: {
            validators: {
                notEmpty: {
                    message: 'Resume file is required' 
                },
                file: {
                    extension: 'doc,docx,pdf,rtf,txt,ppt,pptx',
                    type: 'application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf,application/x-download,application/x-pdf,application/acrobat,applications/vnd.pdf,text/pdf,text/x-pdf,application/rtf,text/plain,application/vnd.ms-powerpoint,application/powerpoint,application/mspowerpoint,application/vnd.ms-office,application/vnd.openxmlformats-officedocument.presentationml.presentation',
                    maxSize: 11000000, 
                    message: 'The selected file is not valid, it should be (doc, docx, pdf, rtf, txt, ppt, pptx) and not more than 10MB in size'
                }
            }   
        }   
    }
})

...........

self.doAddResume = function(){            
        $('input[name=name]').val('');
        $('#resume_file').wrap('<form>').closest('form').get(0).reset();
        $("#resume_name").val('');
        self.showResumeForm(true);
    }
4

0 回答 0