Skip to content

Commit

Permalink
better handling of min/max dates in selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
tipiirai committed Sep 22, 2010
1 parent 66b187a commit 85655d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<project name="jQuery.Tools" default="min">

<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="version" value="1.2.4"/>
<property name="version" value="1.2.5"/>
<property name="build" value="build/${version}"/>
<property name="file" value="none"/>

Expand Down
26 changes: 10 additions & 16 deletions src/dateinput/dateinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,24 +457,18 @@

//{{{ setValue

setValue: function(year, month, day) {
setValue: function(year, month, day) {

var date = integer(month) >= -1 ?
new Date(integer(year), integer(month), integer(day || 1)) : year || value
;

var date;

if (parseInt(month, 10) >= -1) {
// strings to numbers
year = integer(year);
month = integer(month);
day = integer(day);
date = new Date(year, month, day);

} else {
date = year || value;
year = date.getFullYear();
month = date.getMonth();
day = date.getDate();
}
if (date < min) { date = min; }
else if (date > max) { date = max; }

year = date.getFullYear();
month = date.getMonth();
day = date.getDate();


// roll year & month
Expand Down
8 changes: 3 additions & 5 deletions test/dateinput/setmin.htm
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
<link rel="stylesheet" type="text/css" href="skin1.css"/>

<!-- HTML5 date input -->
<input type="date" name="mydate" data-value="2010-12-01" min="2010-12-01" />
<input type="date" name="mydate" data-value="2010-12-01" min="2010-12-01" max="2011-12-02" />

<input type="date" name="mydate" data-value="2010-12-01" min="2010-12-01" />
<input type="date" name="mydate" data-value="2010-12-01" min="2010-12-01" max="2012-07-01" />

<!-- make it happen -->
<script>
$(":date:first").dateinput({selectors: true});

$(":date:last").dateinput({selectors: false});
$(":date").dateinput({selectors: true});
</script>

0 comments on commit 85655d7

Please sign in to comment.