如何使Spring和Dojo需要我的下拉列表(形式:select)? [英] How do I make my dropdowns (form:select) required with Spring and Dojo?

查看:117
本文介绍了如何使Spring和Dojo需要我的下拉列表(形式:select)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使Spring和Dojo需要我的下拉列表(形式:select)?我正在和Dojo一起工作,使我的页面看起来不错。我有输入字段正常工作,但现在我的一个页面有一个下拉列表。如何使我的dojo输入像下拉列表一样,如何使其成为必需。请看下面的代码...

How do I make my dropdowns (form:select) required with Spring and Dojo?. I am working on a Spring project with Dojo to make my pages look nice. I have the input fields working but now one of my pages has a dropdown on it. How can I make the dropdown like the my dojo inputs and how do I make it required. please see code below...

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>


<script type="text/javascript"
    src="<c:url value="/resources/dojo/dojo.js" />">

</script>
<script type="text/javascript"
    src="<c:url value="/resources/spring/Spring.js" />">

</script>
<script type="text/javascript"
    src="<c:url value="/resources/spring/Spring-Dojo.js" />">

</script>

<link type="text/css" rel="stylesheet"
    href="<c:url value="/resources/dijit/themes/claro/claro.css" />" />


<script type="dojo/method" data-dojo-event="onSubmit">
        if(this.validate()){
            return confirm('Form is valid, press OK to submit');
        }else{
            alert('Form contains invalid data.  Please correct first');
            return false;
        }
        return true;
    </script>


<html>
<head>
<title>Spring 3.0 MVC - Web Flow Example</title>
</head>
<body class="claro">
    <h2>Customer Registration</h2>

    <form:form commandName="customer">
        <input type="hidden" name="_flowExecutionKey"
            value="${flowExecutionKey}" />
        <div id="container">
            <table>
                <tr>
                    <td><b>Active</n></td>
                    <td><form:radiobutton tabIndex="1" value="A" path="type"
                            id="A" /></td>
                </tr>
                <tr>
                    <td><b>Retired</b></td>
                    <td><form:radiobutton tabIndex="2" value="R" path="type"
                            id="R" /> <script type="text/javascript">
                                Spring
                                        .addDecoration(new Spring.ElementDecoration(
                                                {
                                                    elementId : 'A',
                                                    widgetType : "dijit.form.RadioButton",
                                                    widgetAttrs : {
                                                        value : "A",
                                                        required : true
                                                    }
                                                }));
                                Spring
                                        .addDecoration(new Spring.ElementDecoration(
                                                {
                                                    elementId : 'R',
                                                    widgetType : "dijit.form.RadioButton",
                                                    widgetAttrs : {
                                                        value : "R",
                                                        required : true
                                                    }
                                                }));
                            </script></td>
                </tr>
                <tr>
                    <td><font color=red><form:errors path="sex" /></font><b>Sex:
                    </b></td>
                    <td><form:select path="sex">
                            <option value="MALE">MALE</option>
                            <option value="FEMALE">FEMALE</option>
                        </form:select> <script type="text/javascript">
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : "name",
                                widgetType : "dijit.form.ValidationTextBox",
                                widgetAttrs : {
                                    promptMessage : "Enter Name",
                                    required : true
                                }
                            }));
                        </script> <br />
                        <p></td>
                </tr>
                <tr>
                    <td><font color=red><form:errors path="name" /></font><b>Name:
                    </b></td>
                    <td><form:input path="name" class="value" /> <script
                            type="text/javascript">
                        Spring.addDecoration(new Spring.ElementDecoration({
                            elementId : "name",
                            widgetType : "dijit.form.ValidationTextBox",
                            widgetAttrs : {
                                promptMessage : "Enter Name",
                                required : true
                            }
                        }));
                    </script> <br />
                        <p></td>
                </tr>
                <tr>
                    <td><font color=red><form:errors path="phoneNumber" /></font>

                        <b>Phone number: </b></td>
                    <td>
                        <div class="span-7 last">
                            <form:input path="phoneNumber" />
                        </div> <script type="text/javascript">
                            Spring
                                    .addDecoration(new Spring.ElementDecoration(
                                            {
                                                elementId : "phoneNumber",
                                                widgetType : "dijit.form.ValidationTextBox",
                                                widgetAttrs : {
                                                    required : true,
                                                    invalidMessage : "A 16-digit credit card number is required.",
                                                    regExp : "[0-9]{16}"
                                                }
                                            }));
                        </script> <br />
                    </td>
                </tr>
                <tr>
                    <td><font color=red><form:errors path="address" /></font> <b>Address:
                    </b></td>
                    <td><form:input path="address" /> <script
                            type="text/javascript">
                        Spring.addDecoration(new Spring.ElementDecoration({
                            elementId : "address",
                            widgetType : "dijit.form.ValidationTextBox",
                            widgetAttrs : {
                                promptMessage : "Enter Address",
                                required : true
                            }
                        }));
                    </script> <br /></td>
                </tr>
                <tr>
                    <td><font color=red><form:errors path="city" /></font> <b>City:
                    </b></td>
                    <td><form:input path="city" /> <script type="text/javascript">
                        Spring.addDecoration(new Spring.ElementDecoration({
                            elementId : "city",
                            widgetType : "dijit.form.ValidationTextBox",
                            widgetAttrs : {
                                promptMessage : "Enter City",
                                required : true
                            }
                        }));
                    </script> <br /></td>
                </tr>
                <tr>
                    <td><font color=red><form:errors path="state" /></font> <b>State:
                    </b></td>
                    <td><form:input path="state" /> <script
                            type="text/javascript">
                        Spring.addDecoration(new Spring.ElementDecoration({
                            elementId : "state",
                            widgetType : "dijit.form.ValidationTextBox",
                            widgetAttrs : {
                                promptMessage : "Enter State",
                                required : true
                            }
                        }));
                    </script> <br /></td>
                </tr>
                <tr>
                    <td><font color=red><form:errors path="zipCode" /></font> <b>Zip
                            Code: </b></td>
                    <td><form:input path="zipCode" /> <script
                            type="text/javascript">
                        Spring.addDecoration(new Spring.ElementDecoration({
                            elementId : "zipCode",
                            widgetType : "dijit.form.ValidationTextBox",
                            widgetAttrs : {
                                promptMessage : "Enter Zip Code",
                                required : true
                            }
                        }));
                    </script> <br /></td>
                </tr>
            </table>
        </div>

        <input type="submit" name="_eventId_submit" id="submit" value="Submit" />
        <input type="submit" name="_eventId_cancel" value="Cancel" />
        <script type="text/javascript">
            Spring.addDecoration(new Spring.ValidateAllDecoration({
                elementId : 'submit',
                event : 'onclick'
            }));
        </script>
    </form:form>

</body>
</html>


推荐答案

看起来像是复制/粘贴错误。首先,您没有任何形式的ID:选择

It looks like copy/paste bug. First of all you don't have any id in your form:select

<form:select path="sex">

另一件事是你的表单中有错误的id:select的装饰器。你将它从form = input与id =name复制。

Another thing is that you have wrong id inside your form:select's decorator. You copied it from form:input with id="name".

Spring.addDecoration(new Spring.ElementDecoration({
                                **elementId : "name",**
                                widgetType : "dijit.form.ValidationTextBox",
                                widgetAttrs : {
                                    promptMessage : "Enter Name",
                                    required : true
                                }
                            }));

这篇关于如何使Spring和Dojo需要我的下拉列表(形式:select)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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