开发者

Struts 1.x html:select with default "no selection" value -- best approach?

In a Struts 1.x application, I have a form with a simple single-selection html:select element. I want to force the user to touch the box and make a choice, rather than allowing the first option to be the de facto default va开发者_如何学运维lue. An obvious first step is to add a stand-in html:option value as the first item in the list. This option would have a label such as "Please choose..." and a marker value of some kind to indicate that this is not a genuine option.

My question: What is the best approach to detect and reject this "no selection" value during form submission?

Ideally, I would like to use a standard Struts validator and the standard error flow, so that this would act in a similar fashion to an html:text with a "required" validator. Is this possible? If not, how can I achieve a similar effect?


I like the approach where the required fields have a red asterisk next to them and the submit button is disabled until a choice has been made. This is pretty trivial to do with javascript (checkout http://docs.jquery.com/Plugins/Validation for a ready to use package).


You could simply have the Please choose... option have value="" then make the field required in your validation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜