希望通過的ErrorMessage控制你的意思是「顯示錯誤」控件。對於「數據」中所有屬性中的組合框,您可以找到「驗證器」。在這裏,您可以像編輯框一樣添加驗證。對於組合框,我通常使用validateExpression
。然後我使用「顯示錯誤」控件來顯示錯誤。
<xp:comboBox id="comboBox1">
<xp:this.validators>
<xp:validateExpression message="Please select value in combo box.">
<xp:this.expression><![CDATA[#{javascript:!getComponent("comboBox1").getSubmittedValue().equalsIgnoreCase("Select")}]]></xp:this.expression>
</xp:validateExpression>
</xp:this.validators>
<xp:selectItem itemLabel="Select" itemValue="Select"></xp:selectItem>
<xp:selectItem itemLabel="1" itemValue="1"></xp:selectItem>
<xp:selectItem itemLabel="2" itemValue="2"></xp:selectItem>
<xp:selectItem itemLabel="3" itemValue="3"></xp:selectItem>
</xp:comboBox>
<xp:message id="message1" for="comboBox1"></xp:message>
在上面的例子中,如果用戶沒有選擇組合框中的任何項目,那麼錯誤消息顯示給用戶。請注意,這是服務器端驗證。我沒有嘗試過其他控件,但它應該以類似的方式工作。
讓我知道如果我正確理解你的問題。
更新2013年2月7日:查看下面的評論Mikael Grevsten爲更好的方法。
我認爲你的意思是這個? http://openntf.org/XSnippets.nsf/snippet.xsp?id=ssjs-form-validation-that-triggers-errormessage-controls我從來沒有能夠得到它的工作。那裏有任何工作實例嗎? –
是的,這是我在我的答案中鏈接到的那個。我使用它在幾個應用程序,所以我有工作的例子。 –
我得到它的工作,但我不喜歡它。它不會將焦點設置爲正在驗證的控件。或者我仍然在做錯什麼? –