Skip to content

Commit

Permalink
default value of date if empty element
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Sep 22, 2012
1 parent dedb91b commit aa4ba14
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -3,6 +3,7 @@ Bootstrap-editable change log

Version 1.1.4 wip
----------------------------
Bug: If date not set it equals to today (@vitalets)
Enh #24: Updated to jquery 1.8.2 (@vitalets)
Enh: Add api method 'submit' to simplify creating new record (@vitalets)
Enh #39: Add api method 'option' to set one or several options dynamically (@vitalets)
Expand Down
4 changes: 3 additions & 1 deletion src/js/bootstrap-editable.js
Expand Up @@ -797,7 +797,9 @@
this.$element.text(text);
},
setValueByText:function () {
this.value = this.settings.converFormat.call(this, this.$element.text(), this.settings.viewformat, this.settings.format);
var text = $.trim(this.$element.text());
if(!text.length) return;
this.value = this.settings.converFormat.call(this, text, this.settings.viewformat, this.settings.format);
},
//helper function to convert date between two formats
converFormat: function(dateStr, formatFrom, formatTo) {
Expand Down
19 changes: 19 additions & 0 deletions test/api.js
Expand Up @@ -59,6 +59,25 @@ $(function () {
e.editable('markAsSaved');
ok(!e.filter('.editable-changed').length, 'editable-changed not exist');
});

test("getValue with originally empty elements", function () {
var e = $(
'<a href="#" data-type="text" id="username"></a>' +
'<a href="#" data-type="textarea" id="comment"></a>' +
'<a href="#" data-type="select" id="sex" data-source=\'{"1":"q", "2":"w"}\'></a>' +
'<a href="#" data-type="date" id="dob"></a>'
).appendTo('#qunit-fixture');

$('#qunit-fixture').find('a').editable();

//check get value
var values = e.editable('getValue');

equal(values.username, '', 'text ok') ;
equal(values.comment, '', 'textarea ok') ;
equal(values.sex, undefined, 'select ok') ;
equal(values.dob, undefined, 'date ok') ;
});

asyncTest("'update' event", function () {
expect(2);
Expand Down
3 changes: 1 addition & 2 deletions test/text.js
Expand Up @@ -17,7 +17,7 @@ $(function () {
equal(p.find('input[type=text]').val(), '', 'input val is empty string')
p.find('button[type=button]').click();
ok(!p.is(':visible'), 'popover was removed')
})
})

test("option 'placeholder'", function () {
var e = $('<a href="#" id="a" data-placeholder="abc"> </a>').appendTo('#qunit-fixture').editable();
Expand All @@ -39,7 +39,6 @@ $(function () {
ok(!p.is(':visible'), 'popover was removed');
});


test("toggle by another element (string)", function () {
var e = $('<a href="#" id="a"></a>').appendTo('#qunit-fixture').editable({
toggle: '<i class="icon-pencil"></i>'
Expand Down

0 comments on commit aa4ba14

Please sign in to comment.