Knockout JS验证消息重复两次

时间:2016-08-16 11:18:49

标签: validation knockout.js

Knockoutjs的新手,只是尝试修复验证消息中的现有错误。下面提到的扩展验证消息在UI中重复两次。

$.each(viewModel.Form.Questions(), function () {
        var currentQuestion = this;
        debugger;
        $.each(currentQuestion.QuestionAnswers(), function () {
            var text = this.AnswerDisplay();
            this.AnswerValue.extend({
                required: {
                    message: text + " : Question price is required",
                    onlyIf: function () {
                        return viewModel.Form.FormPrice.PricingMode() == 2;
                    }
                },
                min: {
                    message: text + " : Question price should be a number",
                    onlyIf: function () {
                        return viewModel.SelectedQuestion() != null && currentQuestion.FormQuestionId() == viewModel.SelectedQuestion().FormQuestionId() && viewModel.Form.FormPrice.PricingMode() == 2;
                    },
                    params: 0
                }
            });
        });
    });

0 个答案:

没有答案