如何检查字段大小,并使弹簧,Spring-JS和DOJO(dijit)所需的单选按钮 [英] How to check field sizes and make radiobutton required with Spring, Spring-JS and DOJO (dijit)

查看:83
本文介绍了如何检查字段大小,并使弹簧,Spring-JS和DOJO(dijit)所需的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring,Spring-JS和DoJo(dijit)开展我的第一个项目,我在以下编码示例中有两个问题。



1)如何检查Dojo(dijit)电话号码字段是否正确,我如何检查名称字段是否大于3而小于50?



2)正如你可以看到我的表单有单选按钮,我需要根据需要设置。如何用Dojo(dijit)做这件事。



谢谢

 <%@ taglib prefix =curi =http://java.sun.com/jstl/core%> 
<%@ taglib prefix =fmturi =http://java.sun.com/jstl/fmt%>
<%@ taglib prefix =formuri =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 =stylesheet
href =< c:url value =/ resources / dijit / themes / claro / claro.css /> />
< html>
< head>
< title> Spring 3.0 MVC - Web流程示例< / title>
< / head>
< body class =claro>
< h2>客户注册< / h2>

< form:form commandName =customer>
< input type =hiddenname =_ flowExecutionKey
value =$ {flowExecutionKey}/>
< div id =container>
< table>
< tr>
< td>< b>活动< / n>< / td>
< td>< form:radiobutton tabIndex =1value =Apath =typeid =A/>< / td>
< / tr>
< tr>
< td>< b>退休< / b>< / td>
< td>< form:radiobutton tabIndex =2value =Rpath =typeid =R/>
< script type =text / javascript>
Spring.addDecoration(new Spring.ElementDecoration({
elementId:'A',
widgetType:dijit.form.RadioButton,
widgetModule:dijit.form.CheckBox ,
widgetAttrs:{value:A,
required:true}
}));
Spring.addDecoration(new Spring.ElementDecoration({
elementId:'R',
widgetType:dijit.form.RadioButton,
widgetModule:dijit.form.CheckBox ,
widgetAttrs:{value:R,
required:true}
}));
< / script>

< / td>
< / tr>
< tr>
< td>< font color = red>< form:errors path =name/>< / font>< b>名称:
< / b> / TD>
< td>< form:input path =nameclass =value/> < script
type =text / javascript>
Spring.addDecoration(new Spring.ElementDecoration({
elementId:name,
widgetType:dijit.form.ValidationTextBox,
widgetAttrs:{
promptMessage :输入名称,需要
:true
}
}));
< / script> < br />
< p>< / td>
< / tr>
< tr>
< td>< font color = red>< form:errors path =phoneNumber/>< / font>

< b>电话号码:< / 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:需要16位数的信用卡号。
regExp:[0-9] {16}
}
}));
< / script> < br />
< / td>
< / tr>
< tr>
< td>< font color = red>< form:errors path =address/>< / font> < b>地址:
< / b>< / td>
< td>< form:input path =address/> < script
type =text / javascript>
Spring.addDecoration(new Spring.ElementDecoration({
elementId:address,
widgetType:dijit.form.ValidationTextBox,
widgetAttrs:{
promptMessage :输入地址,需要
:true
}
}));
< / script> < br />< / td>
< / tr>
< tr>
< td>< font color = red>< form:errors path =city/>< / font> < b>城市:
< / b>< / td>
< td>< form:input path =city/> < script type =text / javascript>
Spring.addDecoration(new Spring.ElementDecoration({
elementId:city,
widgetType:dijit.form.ValidationTextBox,
widgetAttrs:{
promptMessage :进入城市,需要
:true
}
}));
< / script> < br />< / td>
< / tr>
< tr>
< td>< font color = red>< form:errors path =state/>< / font> < b>状态:
< / b>< / td>
< td>< form:input path =state/> < script
type =text / javascript>
Spring.addDecoration(new Spring.ElementDecoration({
elementId:state,
widgetType:dijit.form.ValidationTextBox,
widgetAttrs:{
promptMessage :进入状态,
需要:true
}
}));
< / script> < br />< / td>
< / tr>
< tr>
< td>< font color = red>< form:errors path =zipCode/>< / font> < b> Zip
代码:< / b>< / td>
< td>< form:input path =zipCode/> < script
type =text / javascript>
Spring.addDecoration(new Spring.ElementDecoration({
elementId:zipCode,
widgetType:dijit.form.ValidationTextBox,
widgetAttrs:{
promptMessage :输入邮政编码,需要
:真
}
}));
< / script> < br />< / td>
< / tr>
< / table>
< / div>

< input type =submitname =_ eventId_submitid =submitvalue =提交/>
< input type =submitname =_ eventId_cancelvalue =取消/>
< script type =text / javascript>
Spring.addDecoration(new Spring.ValidateAllDecoration({
elementId:'submit',
event:'onclick'
}));
< / script>
< / form:form>

< / body>
< / html>


解决方案

所以这里是radiobutton的答案,例如:

  Spring.addDecoration(new Spring.ElementDecoration({
elementId:'A',
widgetType:dijit.form.RadioButton,
widgetModule:dijit.form.CheckBox,
validate:function(){
if(dojo.query('INPUT [name = type ];''''''')filter(function(n){return n.checked;})。length> 0){return true;} else {alert('select a type'); return false;}
},
widgetAttrs:...
}));

现在您应该可以使用您的名字字段执行相同的操作


I am working on my first project with Spring, Spring-JS and DoJo(dijit) and I have two questions bases on the following coding example.

1) How do I check with Dojo (dijit) that the phone number field is the right size and also how do I check that the name field is bigger then 3 and less then 50?

2) As you can see my form has radio buttons which I need to set as required. How do I do that with Dojo (dijit).

Thanks

<%@ 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" />" />
<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",
                                widgetModule : "dijit.form.CheckBox",
                                widgetAttrs : { value : "A", 
                                                required : true}
                            }));
                            Spring.addDecoration(new Spring.ElementDecoration({
                                elementId : 'R',
                                widgetType : "dijit.form.RadioButton",
                                widgetModule : "dijit.form.CheckBox",
                                widgetAttrs : { value : "R",
                                                required : true}
                            }));
                        </script>

                    </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>

解决方案

so here is an answer to the radiobutton, with an example:

Spring.addDecoration(new Spring.ElementDecoration({
      elementId : 'A',
      widgetType : "dijit.form.RadioButton",
      widgetModule : "dijit.form.CheckBox",
      validate: function (){
           if(dojo.query('INPUT[name=type]', 'customer').filter(function(n){return n.checked;}).length > 0){return true;} else {alert('choose a type');return false;}
      },
      widgetAttrs : ...
}));

now you should be able to do the same with your name field

这篇关于如何检查字段大小,并使弹簧,Spring-JS和DOJO(dijit)所需的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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