Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow calendar to except empty content

  • Loading branch information...
commit 6295aeacf9f4a9fcc069400fb81fab064744bd79 1 parent eabaa9e
@jamesstrate jamesstrate authored
Showing with 37 additions and 1 deletion.
  1. +4 −1 src/js/calendar.js
  2. +33 −0 test/date_picker.js
View
5 src/js/calendar.js
@@ -43,6 +43,9 @@
render : function() {
if(_(this.model).exists() && _(this.options.content).exists()) {
this.date = this.resolveContent();
+ if(!_(this.date).isDate()) {
+ this.date = new Date();
+ }
var key = 'change:' + this.options.content;
this.model.unbind(key, this.render);
this.model.bind(key, this.render);
@@ -63,7 +66,7 @@
// we only want to set the bound property's date portion
var boundDate = this.resolveContent();
- var updatedDate = new Date(boundDate.getTime());
+ var updatedDate = _(boundDate).isDate() ? new Date(boundDate.getTime()) : new Date();
updatedDate.setMonth(date.getMonth());
updatedDate.setDate(date.getDate());
updatedDate.setFullYear(date.getFullYear());
View
33 test/date_picker.js
@@ -48,6 +48,39 @@ $(document).ready(function() {
});
+ test("withDataBinding content empty", function() {
+ var coffee = new Backbone.Model({
+ roaster: 'Counter Culture',
+ name: 'Baroida',
+ roastedOn: null,
+ acidic: true
+ });
+
+ var datepicker = new Backbone.UI.DatePicker({
+ model: coffee,
+ content: 'roastedOn'
+ }).render();
+
+ //check if date is set to model date
+ var date = $(datepicker.el).find('input').val();
+ equal(date,"");
+
+ //update model and check time picker
+ coffee.set({ roastedOn : new Date(2012,3,1)});
+ date = $(datepicker.el).find('input').val();
+ equal(date,'04/01/2012');
+
+ //pick date and check model
+ $(datepicker.el).find('input').click();
+ datepicker._calendar.$('.row.last td a').eq(0).click();
+ date = $(datepicker.el).find('input').val();
+ equal(date,'04/29/2012');
+ equal(coffee.get('roastedOn').getMonth(),'3');
+ equal(coffee.get('roastedOn').getDate(),'29');
+ equal(coffee.get('roastedOn').getFullYear(),'2012');
+
+ });
+
test("format", function() {
var datepicker = new Backbone.UI.DatePicker({
date : new Date(2013, 2, 22),

0 comments on commit 6295aea

Please sign in to comment.
Something went wrong with that request. Please try again.