Skip to content

Commit

Permalink
Merge pull request #638 from HS2-SOLUTIONS/master
Browse files Browse the repository at this point in the history
Handle empty date values in combodate
  • Loading branch information
eugef authored Mar 21, 2017
2 parents 0de8919 + c7cb0b3 commit 4bcbef6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
29 changes: 29 additions & 0 deletions docs/demos/combodate/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,33 @@ describe('combodate', function() {
expect(element(s+'a[editable-combodate]').text()).toMatch('Apr 29, 1984 12:00:00 AM');
expect(element(s+'form').count()).toBe(0);
});

it('should show editor and submit empty value when empty value is selected in one of the drop downs', function() {
var s = '[ng-controller="CombodateCtrl"] ';

expect(element(s+'a[editable-combodate]').css('display')).not().toBe('none');
expect(element(s+'a[editable-combodate]').text()).toMatch('May 15, 1984 12:00:00 AM');
element(s+'a[editable-combodate]').click();

expect(element(s+'a[editable-combodate]').css('display')).toBe('none');
expect(element(s+'form[editable-form="$form"]').count()).toBe(1);
expect(element(s+'form select:visible').count()).toBe(5);
expect(element(s+'form select.day').val()).toBe('15');
expect(element(s+'form select.month').val()).toBe('4');
expect(element(s+'form select.year').val()).toBe('1984');
expect(element(s+'form select.hour').val()).toBe('0');
expect(element(s+'form select.minute').val()).toBe('0');
expect(element(s+'form .editable-buttons button[type="submit"]:visible').count()).toBe(1);
expect(element(s+'form .editable-buttons button[type="button"]:visible').count()).toBe(1);

//set 29 april
element(s+'form select.day option[value=]').click();

//submit
element(s+'form button[type="submit"]').click();

expect(element(s+'a[editable-combodate]').css('display')).not().toBe('none');
expect(element(s+'a[editable-combodate]').text()).toMatch('empty');
expect(element(s+'form').count()).toBe(0);
});
});
3 changes: 2 additions & 1 deletion src/js/directives/combodate.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ angular.module('xeditable').directive('editableCombodate', ['editableDirectiveFa
var combodate = editableCombodate.getInstance(this.inputEl, options);
combodate.$widget.find('select').bind('change', function(e) {
//.replace is so this works in Safari
self.scope.$data = (new Date(combodate.getValue().replace(/-/g, "/"))).toISOString();
self.scope.$data = combodate.getValue() ?
(new Date(combodate.getValue().replace(/-/g, "/"))).toISOString() : null;
});
}
});
Expand Down

0 comments on commit 4bcbef6

Please sign in to comment.