簡體   English   中英

Dojo形式的驗證

[英]Validation in Dojo Form

我有一個dojo表單,其中有5個字段:其中2個是validationtext box,1個是filteringSelect,2個是NumberText Box。 在單擊搜索按鈕時,我希望用戶在5個字段中至少輸入一個值。 如何應用此驗證?

謝謝

您需要使用dijit/form/Form http://dojotoolkit.org/reference-guide/1.10/dijit/form/Form.html#dijit-form-form

 require(["dojo/parser", "dijit/form/Form", "dijit/form/Button", "dijit/form/ValidationTextBox", "dijit/form/DateTextBox"], function(parser) { document.body.className += ' tundra'; //just to have the proper css in the snippet parser.parse() //to render properly in the snippets //here is the part you are looking for: getValues = function() { console.log(myForm.getValues()); values = myForm.getValues(); var oneHasValue = false; for(var i in values) { if(values[i]) { oneHasValue = true; break; } } if(!oneHasValue) { alert('at least one field should not be empty') } } }); 
 <script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script> <link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/resources/dojo.css"> <link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/tundra/tundra.css"> <div data-dojo-type="dijit/form/Form" id="myForm" data-dojo-id="myForm" encType="multipart/form-data" action="" method=""> <table style="border: 1px solid #9f9f9f;" cellspacing="10"> <tr> <td> <label for="name">Name:</label> </td> <td> <input type="text" id="name" name="name" required="true" data-dojo-type="dijit/form/ValidationTextBox"/> </td> </tr> <tr> <td> <label for="gender">gender:</label> </td> <td> <input type="text" id="gender" name="gender" required="true" data-dojo-type="dijit/form/ValidationTextBox"/> </td> </tr> <tr> <td> <label for="extra">extra info:</label> </td> <td> <input type="text" id="extra" name="extra" required="true" data-dojo-type="dijit/form/ValidationTextBox"/> </td> </tr> <tr> <td> <label for="dob">Date of birth:</label> </td> <td> <input type="text" id="dob" name="dob" data-dojo-type="dijit/form/DateTextBox"/> </td> </tr> </table> <button data-dojo-type="dijit/form/Button" type="button" onClick="getValues()">Get Values from form!</button> </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM