我試圖讓我的代碼中的Dojo NumberTextBox工作,並且出於某種原因,當我將它「移植」到我的網站時,示例代碼不工作。我直接從Dojo 1.9文檔拉到這個例子的代碼,它的工作原理:Dojo 1.9 NumberTextBox不工作?
<html >
<head>
<link rel="stylesheet" href="../../_static/js/dojo/../dijit/themes/claro/claro.css">
<script>dojoConfig = {async: true, parseOnLoad: true}</script>
<script src='../../_static/js/dojo/dojo.js'></script>
<script>
require(["dojo/parser", "dijit/form/NumberTextBox"]);
</script>
</head>
<body class="claro">
<label for="q05">Integer between -20000 to +20000:</label>
<input id="q05" type="text"
data-dojo-type="dijit/form/NumberTextBox"
name= "elevation"
required="true"
value="3000"
data-dojo-props="constraints:{min:-20000,max:20000,places:0},
invalidMessage:'Invalid elevation.'" />
</body>
</html>
這裏是我的JSP代碼,它開始生活作爲一系列JSP頁面。正如你所看到的,我有需要()塊和我覺得進口它的正確放置(它顯示在HTML頁面的頭部):
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/dojo.js.uncompressed.js"></script>
<script src="${pageContext.request.contextPath}/js/mystuff.js"></script>
<script type="text/javascript" >
dojoConfig={async: true, parseOnLoad: true};
require(["dojo/parser", "dijit/form/NumberTextBox"]);
</script>
<form:form id="formInfo" commandName="formInfo" action="${flowExecutionUrl}" enctype="multipart/form-data">
<div id="YIBOtherContainer" style="display:none;"> <%-- hidden to start with --%>
<form:input id="yearsInBusinessOther" path="yearsInBusinessOther"
data-dojo-type="dijit/form/NumberTextBox"
data-dojo-props="constraints:{min:6,max:99,places:0}, invalidMessage:'Invalid value.'" />
<div class="formRow otherIndent">
<form:errors cssClass="formError" path="yearsInBusinessOther" />
</div>
</div>
</form:form>
而這裏的HTML INPUT標記,上面的JSP代碼產生:
<input id="yearsInBusinessOther" name="yearsInBusinessOther" data-dojo-props="constraints:{min:6,max:99,places:0}, invalidMessage:'Invalid value.'" data-dojo-type="dijit/form/NumberTextBox" type="text" value="99"/>
但是沒有驗證。我可以在表單字段中輸入任何內容,並且我從不收到錯誤消息,更改格式或其他任何內容,以表明任何驗證正在觸發。
知道Dojo 1.9的人可以看看這個並希望指出我做錯了什麼嗎?
謝謝!這些小東西總讓我把頭髮拉出來。 – user3120173