0

我正在为我的项目使用验证淘汰赛并且我对所有错误消息都使用了模板:

    <script type="text/html" id="errorTemplate">
        <div class="errorContainer error_bottom" data-bind="visible: field.isModified() && !field.isValid()">
        <div class="error_arrow">
        <div class="error_arrow_inner"></div>            
        </div>
        <span class="error" data-bind="text: field.error"></span>
        </div>
    </script>

<script>
    // KO validastor setup:
    ko.validation.configure({
        decorateElement: true,
        errorElementClass: 'error', // Add class to input
        registerExtenders: true,
        messagesOnModified: true,
        insertMessages: true,
        parseInputAttributes: true,
        messageTemplate: 'errorTemplate' // Use template 
    });

    function ReservationViewModel() {
            var self = this;
            self.email = ko.observable("");
            self.name = ko.observable("");
            self.phone = ko.observable("");

            var validator = ko.validatedObservable({
                email: self.email.extend({required: true, email: true}),
                name: self.name.extend({required: true}),
                phone: self.phone.extend({required: true}),
            });
    // continues ...
    }

    ko.applyBindings(new ReservationViewModel());
</script>

但它总是得到默认消息:“此字段是必需的。” 对于自定义错误或电子邮件无效。你能帮我修一下吗?谢谢大家。

4

0 回答 0