防止在表单无效时触发操作

时间:2015-10-01 17:20:14

标签: ember.js parsley.js

我正在使用parsleyjs来验证我的表单,我想知道是否有办法防止在表单无效时调用ember操作。

2 个答案:

答案 0 :(得分:1)

如果表单无效,请在您的操作中验证表单,显示错误消息并致电return;

答案 1 :(得分:0)

是的我尝试从操作中验证表单但是我找不到将表单对象传递给控制器​​操作的方法

<script>

    var parlseyForm;

    $(document).ready(function () {
        parsleyForm = $("#editLeagueForm").parsley();
    });

</script>


<div class="mbs-btn-bar">

    <button class="btn btn-default" role="button" {{action "cancel"}}>{{t 'action.cancel'}}</button>
    <!--
    <button type="button" class="btn btn-primary" role="button" onclick="validateForm(this)">{{t 'action.update'}}</button>
    -->

    <button type="button" id="updateLeague" class="btn btn-primary" role="button" {{action "updateLeague" parsleyForm}}>{{t 'action.update'}}</button>
</div>

actions: {
    /**
     * This action is responsible to update the league.
     */
    updateLeague: function (form) {

        alert(form); //undefined

        this.get('model').save().then(() => {
            if (this.isNewFile()) {
                this.uploadAvatar();
            } else {
                this.notifyRoute('league', 'info.league.updated');
            }
        }).catch((error) => {
            this.handleError(error, 'error.system_error');
        });
    },
相关问题