|
<! DOCTYPE html>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Script type = "text/javascript" djConfig = "parseOnLoad: true"
Src = "js/dojo. js"> </script>
<Link rel = "stylesheet" type = "text/css"
Href = "js/dojo/resources/dojo.css"/>
<Link rel = "stylesheet" type = "text/css"
Href = "js/dijit/themes/claro/claro.css"/>
<Title> Dojo Test </title>
<Script type = "text/javascript">
Dojo. require ("dijit. form. DateTextBox ");
Dojo. declare ("net. yutuo. dojo. DateTextBox", [dijit. form. DateTextBox], {
Validator: function (value, constraints ){
Value = this. myParse (value, constraints );
Return (new RegExp ("^ (? : "+ This. regExpGen (constraints) +") "+ (this. required? "":"? ") +" $ "). Test (value)
&&(! This. required |! This. _ isEmpty (value ))
& (This. _ isEmpty (value) | this. parse (value, constraints )! = Undefined );
},
Parse: function (value, constraints ){
Value = this. myParse (value, constraints );
Return this. dateLocaleModule. parse (value, constraints)
| (This. _ isEmpty (value )? Null: undefined );
},
MyParse: function (value, constraints ){
Var dateStr = null;
If (value. match (/^ d {6} $ /)){
DateStr = value. substring (0, 2) + '-' + value. substring (2, 4) + '-' + value. substring (4, 6 );
} Else if (value. match (/^ d {8} $ /)){
DateStr = value. substring (0, 4) + '-' + value. substring (4, 6) + '-' + value. substring (6, 8 );
} Else if (value. match (/^ d {4} $ /)){
DateStr = new Date (). getFullYear () + '-' + value. substring (0, 2) + '-' + value. substring (2, 4 );
}
If (dateStr ){
Var date = this. dateLocaleModule. parse (dateStr, {selector: 'date', datePattern: 'yy-M-d '});
If (date ){
Return this. dateLocaleModule. format (date, constraints );
}
}
Return value;
}
});
</Script>
</Head>
<Body class = "claro">
Old: <br/>
<Input type = "text" data-dojo-type = "dijit. form. DateTextBox"/>
<Br/>
New: <br/>
<Input type = "text" data-dojo-type = "net. yutuo. dojo. DateTextBox"/>
</Body>
</Html> |