Skip to content

Commit

Permalink
Merge pull request #1280 from acrobat/readonly-option
Browse files Browse the repository at this point in the history
Added option to not show datepicker on readonly field
  • Loading branch information
acrobat committed Mar 4, 2015
2 parents c2a03d9 + f70fc92 commit 653ae5d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,10 @@ disableTouchKeyboard
Boolean. Default: false

If true, no keyboard will show on mobile devices

enableOnReadonly
----------------

Boolean. Default: true

If false the datepicker will not show on a readonly datepicker field.
3 changes: 2 additions & 1 deletion js/bootstrap-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@
},

show: function(){
if (this.element.attr('readonly'))
if (this.element.attr('readonly') && this.o.enableOnReadonly === false)
return;
if (!this.isInline)
this.picker.appendTo(this.o.container);
Expand Down Expand Up @@ -1531,6 +1531,7 @@
todayHighlight: false,
weekStart: 0,
disableTouchKeyboard: false,
enableOnReadonly: true,
container: 'body'
};
var locale_opts = $.fn.datepicker.locale_opts = [
Expand Down
29 changes: 29 additions & 0 deletions tests/suites/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,3 +904,32 @@ test('Default View Date', function(){

equal(picker.find('.datepicker-days thead .datepicker-switch').text(), 'May 1977');
});

//datepicker-dropdown

test('Enable on readonly options (default)', function(){
var input = $('<input readonly="readonly" />')
.appendTo('#qunit-fixture')
.datepicker({format: "dd-mm-yyyy"}),
dp = input.data('datepicker'),
picker = dp.picker;

ok(!picker.is(':visible'));
input.focus();
ok(picker.is(':visible'));
});

test('Enable on readonly options (false)', function(){
var input = $('<input readonly="readonly" />')
.appendTo('#qunit-fixture')
.datepicker({
format: "dd-mm-yyyy",
enableOnReadonly: false
}),
dp = input.data('datepicker'),
picker = dp.picker;

ok(!picker.is(':visible'));
input.focus();
ok(!picker.is(':visible'));
});

0 comments on commit 653ae5d

Please sign in to comment.