0

我已经实现了一个名为 Bootstrap Form Wizard 的插件。有人用吗?

我正在进行使用引导程序并创建一些表单向导来创建事务的项目。但是,表单向导验证根本不起作用。

这是我为执行向导所做的语法

  1. 功能验证

    function validateText(el) {
    var name = el.val();
    var retValue = {};
    
    if (name == "") {
        retValue.status = false;
        retValue.msg = "Please enter a name";
    }
    else {
        retValue.status = true;
    }
    
    return retValue;
    

    }

  2. 我的表单向导

        wizard.on("submit", function(wizard) {
                $.ajax({
                    url: "functions/savetransaction.php",
                    type: "POST",
                    data: wizard.serialize(),
                    success: function() {
                        wizard.submitSuccess(); // displays the success card
                        wizard.hideButtons(); // hides the next and back buttons
                        wizard.updateProgressBar(0); // sets the progress meter to 0
                        //wizard.reset();
                    },
                    error: function() {
                        wizard.submitError(); // display the error card
                        wizard.hideButtons(); // hides the next and back buttons
                    }
                }); //end ajax wizard
            }); //end submit wizard 
    
            wizard.on("reset", function(wizard) {
                $.each(wizard.cards, function(name, card) {
                    card.el.find("input").val(""); // resets all inputs on a card to ""
                });
            });
    
            wizard.el.find(".wizard-success .im-done").click(function() {
                //rest all if clicked
                resetForm();
                wizard.reset().close();
            });
    
            wizard.el.find(".wizard-success .create-another-trn").click(function() {
                resetForm();
                wizard.reset();
            });
    
  3. 最后是 HTML

    <div class="wizard-card" data-cardname="card2">
            <h3>User Accounts</h3>
            <label>User</label>
            <input type="text" placeholder="user" id="add_trc_user" name="user" required="true" maxlength="45" data-validate="validateText"/>
    

这里有人知道我的问题吗?

谢谢你!

4

1 回答 1

0

我只是试图重现您的问题,但以下代码对我有用(几乎全部从您的基本代码复制)。

<!DOCTYPE html>
<html>
<head>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="bootstrap-wizard.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
    <script src="bootstrap-wizard.min.js"></script>
</head>
<body>
    <div id="wizard" class="wizard">
        <div class="wizard-card" data-cardname="card2">
            <h3>User Accounts</h3>
            <label>User</label>
            <input type="text" placeholder="user" id="add_trc_user" name="user" required="true" maxlength="45" data-validate="validateText"/>
        </div>
    </div>

    <script type="text/javascript">
    $(function(){
        var wizard = $('#wizard').wizard();
        wizard.show();

        wizard.on("submit", function(wizard) {
            $.ajax({
                url: "functions/savetransaction.php",
                type: "POST",
                data: wizard.serialize(),
                success: function() {
                    wizard.submitSuccess(); // displays the success card
                    wizard.hideButtons(); // hides the next and back buttons
                    wizard.updateProgressBar(0); // sets the progress meter to 0
                    //wizard.reset();
                },
                error: function() {
                    wizard.submitError(); // display the error card
                    wizard.hideButtons(); // hides the next and back buttons
                }
            }); //end ajax wizard
        }); //end submit wizard 

        wizard.on("reset", function(wizard) {
            $.each(wizard.cards, function(name, card) {
                card.el.find("input").val(""); // resets all inputs on a card to ""
            });
        });

        wizard.el.find(".wizard-success .im-done").click(function() {
            //rest all if clicked
            resetForm();
            wizard.reset().close();
        });

        wizard.el.find(".wizard-success .create-another-trn").click(function() {
            resetForm();
            wizard.reset();
        });


    });

 function validateText(el) {
    var name = el.val();
    var retValue = {};

    if (name == "") {
        retValue.status = false;
        retValue.msg = "Please enter a name";
    }
    else {
        retValue.status = true;
    }

    return retValue;
}
</script>
</body>
</html>
于 2013-10-31T20:28:18.020 回答