Revision: 4716 http://sourceforge.net/p/vexi/code/4716 Author: mkpg2 Date: 2014-08-07 21:47:56 +0000 (Thu, 07 Aug 2014) Log Message: ----------- Fix regression. Date entry was broken (not same as the display format).
Modified Paths: -------------- branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datefield.t branches/vexi3/org.vexi-vexi.widgets/src_test/test/widget/datefield.t Added Paths: ----------- branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield_month.t Modified: branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datefield.t =================================================================== --- branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datefield.t 2014-08-05 18:09:58 UTC (rev 4715) +++ branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datefield.t 2014-08-07 21:47:56 UTC (rev 4716) @@ -280,11 +280,13 @@ } static.textWrite = function(v) { - var d = new vexi.js.Date(); - trapee.value = d.tryParseString(v); + trapee.value = static.parseDate(v, trapee.displayformat); } - /** sets the display format */ + + + // SHOULD support more than DDMMYYYY + /** sets the display format static.displayformatWrite = function(v) { switch (v) { case "DDMMYYYY": @@ -312,16 +314,9 @@ throw "Unsupported format: "+v; } cascade = v; - } + }*/ + - static.textRead = function() { - return trapee.value+""; - } - - static.textWrite = function(v) { - trapee.value = vexi.js.Date.tryParseString(v); - } - static.viewsepWrite = function(v) { cascade = v; trapee.dateview[1].text = v; @@ -333,9 +328,86 @@ for(var i,b in trapee.dateview){ b[trapname] = v; } + }; + + + const Date = vexi.js.Date; + const parseInt = function(s){ + return vexi.string.parseInt(s,10); + }; + /** allow input of 00xx years */ + const expandYear = function(ystr) { + if (2>=ystr.length) { + var d = Date.today.year; + // auto-fill year to this year + if (ystr=="") { + return d; + } else { + // auto-expand 2-digit years + ystr = parseInt(ystr); + return (d+10>=ystr ? 2000 : 1900) + ystr; + } + } else return parseInt(ystr); } + /** takes a string 'v' and parses it as a date for 'o' */ + static.parseDate = function(v, format) { + if(format==null) format="DDMMYYYY"; + // establish how many characters for each part + var mc = format.charAt(0); + var m1, m2, mn; + var m3 = format.length; + for (var i=1; m3>i; i++) { + mn = format.charAt(i); + if (mc!=mn) { + if (mc) { + if (!m1) m1 = i; + else if (!m2) m2 = i; + else break; + } + mc = mn; + } + } + // parse string into 3 number parts + var s0 = ""; + var s1 = ""; + var s2 = ""; + var i = 0; + var j = 0; + try { + for (var c = v.charCodeAt(i); c>57 or 48>c; c = v.charCodeAt(++i)) { /* skip non-numbers */ } + for (var c = v.charCodeAt(i); m1>j and c>47 and 58>c; c = v.charCodeAt(++i)) { s0 = s0 + v.charAt(i); j++; } + for (var c = v.charCodeAt(i); c>57 or 48>c; c = v.charCodeAt(++i)) { /* skip non-numbers */ } + for (var c = v.charCodeAt(i); m2>j and c>47 and 58>c; c = v.charCodeAt(++i)) { s1 = s1 + v.charAt(i); j++; } + for (var c = v.charCodeAt(i); c>57 or 48>c; c = v.charCodeAt(++i)) { /* skip non-numbers */ } + for (var c = v.charCodeAt(i); m3>j and c>47 and 58>c; c = v.charCodeAt(++i)) s2 = s2 + v.charAt(i); + } catch (e) { throw "unsupported text value for datefield: '"+v+"'"; } + + const t = Date.today; + var d = !s0 or !s1 or !s2 ? vexi.date() : null; + // assign values to widget + switch (format) { + case "MMDDYYYY": + s0 = s0 ? parseInt(s0) : t.month; + s1 = s1 ? parseInt(s1) : t.day; + s2 = expandYear(s2); + return new Date("YMD", s2,s0,s1); + case "YYYYMMDD": + s0 = expandYear(s0); + s1 = s1 ? parseInt(s1) : t.month; + s2 = s2 ? parseInt(s2) : t.day;; + return new Date("YMD", s0,s1,s2); + case "DDMMYYYY": + default: + s0 = s0 ? parseInt(s0) : t.day; + s1 = s1 ? parseInt(s1) : t.month; + s2 = expandYear(s2); + return new Date("YMD", s2,s1,s0); + } + }; + + /** TODO - REMOVE static.valueformatWrite = function(v) { switch (v) { @@ -373,15 +445,8 @@ default: return ""; } } + - static.textWrite = function(v) { - if (v == "") { - trapee.value = null; - return; - } - trapee.parseDate(v, trapee.textformat, trapee); - } - static.valueRead = function() { switch (trapee.valuetype) { case "vexi.util.date": Copied: branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield_month.t (from rev 4715, branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield.t) =================================================================== --- branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield_month.t (rev 0) +++ branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield_month.t 2014-08-07 21:47:56 UTC (rev 4716) @@ -0,0 +1,41 @@ +<!-- public domain --> + +<vexi xmlns:ui="vexi://ui" xmlns:w="vexi.widget" xmlns:poke="poke"> + <w:surface /> + <ui:box orient="vertical"> + <!--ui:box> + <w:datefield id="date1" inputformat="DDMMYYYY" valueformat="DD-MM-YYYY" /> + <w:datefield id="date2" inputformat="DDMMYYYY" valueformat="YY-MM-DD" /> + </ui:box--> + <ui:box> + <w:monthfield id="date3" inputformat="MMYYYY" valueformat="MM-YYYY" /> + <w:button id="put" text="- Put ->" /> + <w:monthfield id="date4" inputformat="YYYYMM" valueformat="01-MM-YYYY" /> + </ui:box> + <ui:box> + <ui:box> + <w:button id="clear3" text="Clear" /> + </ui:box> + <ui:box /> + <ui:box> + <w:button id="clear4" text="Clear" /> + </ui:box> + </ui:box> + <ui:box> + <ui:box id="date3_label" /> + <ui:box /> + <ui:box id="date4_label" /> + </ui:box> + + $clear3.action ++= function(v) { $date3.value = null; return; } + $clear4.action ++= function(v) { $date4.value = null; return; } + + $put.action ++= function(v) { $date4.value = $date3.value; return; } + + $date3.value ++= function(v) { cascade = v; $date3_label.text = v; } + $date4.value ++= function(v) { cascade = v; $date4_label.text = v; } + + vexi.ui.frame = thisbox; + + </ui:box> +</vexi> Modified: branches/vexi3/org.vexi-vexi.widgets/src_test/test/widget/datefield.t =================================================================== --- branches/vexi3/org.vexi-vexi.widgets/src_test/test/widget/datefield.t 2014-08-05 18:09:58 UTC (rev 4715) +++ branches/vexi3/org.vexi-vexi.widgets/src_test/test/widget/datefield.t 2014-08-07 21:47:56 UTC (rev 4716) @@ -11,6 +11,21 @@ /// Quick Suite var suite = { name: "vexi.widget.datefield Tests" }; + suite.test_entry = function() { + + const assertTextWrite = function(expected, entered){ + var b = new .datefield(); + b.text = entered;; + assertEq(expected, ""+b.value); + }; + assertTextWrite("2012-12-12", "12122012"); + assertTextWrite("2012-12-12", "121212"); + assertTextWrite("2012-12-12", "12-12-12"); + assertTextWrite("2012-01-01", "1/1/12"); + assertTextWrite("1234-12-12", "12121234"); + assertTextWrite("0101-01-01", "01010101"); + }; + suite.test_format = function() { var b = new .datefield(); b.format = "YYYY-MM-DD"; @@ -68,6 +83,6 @@ static.test = suite; <surface> - static.test().testQ1(); + static.test.test_entry(); </surface> </vexi> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Infragistics Professional Build stunning WinForms apps today! Reboot your WinForms applications with our WinForms controls. Build a bridge from your legacy apps to the future. http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn