Dojo电子邮件和URL验证未触发

时间:2014-03-11 19:21:31

标签: javascript jsp dojo

我实施了 DOJO 框架但是我在使用内置验证来处理电子邮件和网址时遇到了问题。似乎函数没有触发是我的代码和我的目录结构的屏幕截图:

Page.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

 <script src="dojo/dojo/dojo.js" data-dojo-config="async:true"></script>


<script>
//load requirements for declarative widgets 

require(["dojo/parser", 
            /* dojox/ validate resources */
            "dojox/validate/us", "dojox/validate/web",
            /* basic dijit classes */
            "dijit/form/CheckBox", "dijit/form/Textarea", "dijit/form/FilteringSelect", "dijit/form/TextBox", "dijit/form/ValidationTextBox", "dijit/form/DateTextBox", "dijit/form/TimeTextBox", "dijit/form/Button", "dijit/form/RadioButton", "dijit/form/Form", "dijit/form/DateTextBox",
            /* basic dojox classes */
            "dojox/form/BusyButton", "dojox/form/CheckedMultiSelect",
            "dojo/domReady!"]);
</script>

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


<title>Insert title here</title>
</head>
<body class="class">
    <form data-dojo-type="dijit/form/Form" method="post"> 

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

        <label for="value1Box">A textbox set with a value from the above textbox:</label><br/>

        <input type="text" required="true" name="firstName" id="firstName" placeholder="Your Name" 
        data-dojo-type="dojo/dijit/form/ValidationTextBox" missingMessage="Ooops!  You forgot your first name!" /><br/>

        <input type="text" required="true" name="website" id="website" placeholder="Your Website" 
        data-dojo-type="dijit/form/ValidationTextBox" validator="dojox.validate.isUrl" /><br/>

        <input type="text" required="true" name="email" id="email" 
        data-dojo-type="dijit/form/ValidationTextBox" validator="dojox.validate.isEmailAddress" /><br/>

        <input type="submit" value="Submit Form" label="Submit Form" 
        id="submitButton" data-dojo-type="dijit/form/Button" />
    </form>

</body>
</html>

目录结构

Dojo Directory Structure

1 个答案:

答案 0 :(得分:1)

您在以下HTML中使用了错误的类型:

<input type="text" required="true" name="firstName" id="firstName" placeholder="Your Name" 
    data-dojo-type="dojo/dijit/form/ValidationTextBox" missingMessage="Ooops!  You forgot your first name!" />

正如您在此处所看到的,您在这里使用了dojo/dijit/form/ValidationTextBox,但它应该像其他两个一样dijit/form/ValidationTextBox

如果你这样做,它应该正常工作,至少它在fiddle