2013-08-27 57 views
8

我使用基因敲除驗證插件,它的工作正常,但我有一個小問題,我想通過使用css使驗證跨度稍微小一些,但更突出,我只想插入驗證跨度就在輸入元素之前,現在是它在輸入元素之後的追加跨度。基因敲除驗證錯誤消息跨度

這裏是如何的渲染,現在,

<input id="personName" class="form-control placeholder has-error" type="text" data-bind="value: name" placeholder="Your name" title="This field is required." data-orig-title=""> 
<span class="validationMessage" style="">This field is required.</span> 

所以我只想元素之前,這個跨度追加。

回答

16

如果要定製錯誤消息的顯示方式,您需要使用預定義的validation bindings,在這種情況下爲validationMessage

使用這種結合可以爲一個給定的顯示屬性的驗證消息,無論你的input元素之前想的那麼例如:

<span data-bind="validationMessage: name"></span> 
<input id="personName" class="form-control placeholder has-error" type="text" 
     data-bind="value: name" 
     placeholder="Your name" title="This field is required." data-orig-title=""> 

此外,以避免雙重顯示你還需要turn off the automatic message insertion與錯誤信息:

ko.validation.init({insertMessages: false}); 

演示JSFiddle

+0

完美的男人! 。你很棒 。非常感謝 – Ancient