How to show validation error messge on different location?

感情迁移 提交于 2020-01-12 02:50:07

问题


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?


回答1:


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

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

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.

Demo JSFiddle.



来源:https://stackoverflow.com/questions/12991515/how-to-show-validation-error-messge-on-different-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!