Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

input-calendar-sync: allow blank date

  • Loading branch information...
commit 0c34e3847e932b8aa5ebac2daeb4e2f3a4753a34 1 parent 231e128
@jafl authored
View
27 input-calendar-sync/gallery-input-calendar-sync-debug.js
@@ -40,6 +40,19 @@ InputCalendarSync.ATTRS =
{
return (value instanceof Y.Calendar);
}
+ },
+
+ /**
+ * Set to false to require a date to be entered.
+ *
+ * @attribute allowBlank
+ * @type {Boolean}
+ * @default true
+ */
+ allowBlank:
+ {
+ value: true,
+ validator: Y.Lang.isBoolean
}
};
@@ -54,7 +67,7 @@ function syncFromInput()
cal = this.get('calendar'),
value = Y.Lang.trim(host.get('value'));
- if (value)
+ if (value.length > 0)
{
try
{
@@ -73,9 +86,17 @@ function syncFromInput()
{
this.ignore_selection_change = false;
}
- }
- privateSyncFromCalendar.call(this);
+ privateSyncFromCalendar.call(this);
+ }
+ else if (!this.get('allowBlank'))
+ {
+ privateSyncFromCalendar.call(this);
+ }
+ else
+ {
+ cal.deselectDates();
+ }
}
function syncFromCalendar()
View
22 input-calendar-sync/index.html
@@ -21,6 +21,9 @@
<form onsubmit="return false;">
<label for="date">Date:</label><input type="text" id="date" value="2012-1-1" />
<div id="calendar"></div>
+ <br>
+ <label for="date2">Date:</label><input type="text" id="date2" placeholder="No date" />
+ <div id="calendar2"></div>
</form>
<script type="text/javascript">
@@ -42,7 +45,8 @@
var node = Y.one('#date');
node.plug(Y.Plugin.InputCalendarSync,
{
- calendar: cal
+ calendar: cal,
+ allowBlank: false
});
// test compatibility with valuechange
@@ -52,6 +56,22 @@
Y.log('previous value: ' + e.prevVal);
Y.log('new value: ' + e.newVal);
});
+
+ // allow blank date
+
+ var cal2 = new Y.Calendar(
+ {
+ width: 300,
+ showPrevMonth: true,
+ showNextMonth: true
+ });
+ cal2.render('#calendar2');
+
+ var node2 = Y.one('#date2');
+ node2.plug(Y.Plugin.InputCalendarSync,
+ {
+ calendar: cal2
+ });
});
</script>
Please sign in to comment.
Something went wrong with that request. Please try again.