如何在不同位置显示验证错误消息? [英] How to show validation error messge on different location?

查看:85
本文介绍了如何在不同位置显示验证错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用knockout.js & knockout.validation插件.我要添加小提琴示例

I am using knockout.js & knockout.validation plugins. I am adding the example fiddle

http://jsfiddle.net/hsnCW/1/

在此示例中,对数组进行了自定义验证,以检查重复的条目.但是我的问题是验证消息.默认情况下,错误消息仅在应用验证的元素之后插入.但是我想在其他地方显示消息.我该怎么办?

In this example there is a custom validation for array to check duplicate entries. But my problem is with the validation message. By default the error message inserted just after the element on which validation is applied.But i want to show message on some different place. How can i do this?

推荐答案

您可以使用validationMessagebinding显示任何属性错误消息:

You can use the validationMessagebinding to display any of your proerties error message:

<p data-bind="validationMessage: newItem"></p>

您可以使用validationOptions绑定禁用自动插入的验证消息:

And you can disable the automatically inserted validation message with the validationOptions binding:

<span data-bind="validationOptions: { insertMessages: false}">New Item: 
    <input data-bind="value:newItem" /> 
    <button data-bind="click: addItem">Add</button>
</span>

有关更多信息,请参见文档验证绑定"部分.

See the documentation Validation Bindings section for more info.

演示 JSFiddle.

这篇关于如何在不同位置显示验证错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆