0

我正在使用向导中的 twitter 引导程序,我想在向导中提交 4 个表单, http: //vadimg.com/twitter-bootstrap-wizard-example/examples/basic-formvalidation.html#

以下是我在每次按下下一个按钮时的代码,

       onNext: function (tab, navigation, index) {
        if(index == 1) {
            if(form_header.valid() === true) {

                    $('#report_header_fm').submit(function(){
                    console.log('test123');
                    $.ajax({
                        type: "POST",
                        url: baseURL + "index.php/addNewReport",
                        data: $("#report_header_fm").serialize(),
                        success: function(data)
                        {
                            console.log('test');
                        }

                        });  //Ajax end
                });

                }
            else
            {
                 return false;
            }
            }
            handleTitle(tab, navigation, index);

            },

我有 5 个输入和 id=report_header_fm 的表格,

现在当我点击下一步时,我可以看到表单验证发生但表单没有被提交,注意 - 我没有点击提交按钮,但有下一步按钮 -

<input type="submit" class="btn green-haze" value="Save">

所以我想要的是在单击下一步时提交表单,单击下一步时会发生验证,但没有发生提交,我在控制台中看不到“test123”,

简而言之,我如何在不点击提交按钮的情况下提交表单?

谢谢,

4

3 回答 3

2

这是您可以在此处更改以使其正常工作的内容列表,希望如此。试试看。

onNext: function (tab, navigation, index) {
        var wizard = this;
        if(index == 1) {
            if(form_header.valid() === true) {
                    //below line are not needed, so comment it out 
                    //$('#report_header_fm').submit(function(){
                    console.log('test123');
                    $.ajax({
                        type: "POST",
                        url: baseURL + "index.php/addNewReport",
                        data: $("#report_header_fm").serialize(),
                        success: function(data)
                        {
                            console.log('test');
                            //At this point you will need to call the show method with index of tab you want to move to.
                            wizard.show(2);
                        }

                        });  //Ajax end
                //});
                  // this would run before the ajax completes
                  return false;
            } else {
                 return false;
            }
 }
于 2015-07-03T06:53:01.320 回答
0
onNext: function (tab, navigation, index) {
                if(index == 1) {
            if(form_header.valid() === true) {

                    console.log('test123');
                    $.ajax({
                        type: "POST",
                        url: baseURL + "index.php/addNewReport",
                        data: $("#report_header_fm").serialize(),
                        success: function(data)
                        {
                            console.log('test');
                           //index of tab 
                           // this will move to next tab only after getting successful response    
                           $('#rootwizard').bootstrapWizard('show',1);
                        }

                        });  //Ajax end

                 //required so that control does not move to next tab unless response is fetched
                  return false;
            } else {
                 return false;
            }
 }
于 2016-07-21T06:19:49.660 回答
0
onNext: function (tab, navigation, index) {
    if(index == 1) {
        if(form_header.valid() === true) {
                $.ajax({
                    type: "POST",
                    url: baseURL + "index.php/addNewReport",
                    data: $("#report_header_fm").serialize(),
                    success: function(data)
                    {
                        console.log('test');
                        this.show(2);
                    }

                    });
        } else {
             return false;
        }
 }
于 2016-04-25T05:59:36.477 回答