Fixes #3291 - Date and Datetime widgets can not be disabled

This commit is contained in:
Mantas 2020-11-18 17:48:45 +02:00 committed by Thorsten Eckel
parent a9a7b97e7a
commit f0fa4a6f9b
3 changed files with 16 additions and 9 deletions

View file

@ -1,4 +1,4 @@
<div class="control controls--date" data-name="<%= @attribute.nameRaw %>">
<input type="hidden" value="<%= @attribute.value %>" name="<%= @attribute.name %>">
<input type="text" value="" class="form-control js-datepicker <%= @attribute.class %>" data-item="date">
</div>
<input type="text" value="" class="form-control js-datepicker <%= @attribute.class %>" data-item="date" <% if @attribute.disabled: %> disabled<% end %>>
</div>

View file

@ -1,6 +1,6 @@
<div class="controls controls--datetime" data-name="<%= @attribute.nameRaw %>">
<input type="hidden" value="<%= @attribute.value %>" name="<%= @attribute.name %>">
<input type="text" value="" class="form-control flex-shrink-horizontal js-datepicker <%= @attribute.class %>" data-item="date">
<input type="text" value="" class="form-control flex-shrink-horizontal js-datepicker <%= @attribute.class %>" data-item="date" <% if @attribute.disabled: %> disabled<% end %>>
<div class="controls-label"><%- @T('at') %></div>
<input type="text" value="" class="form-control time js-timepicker <%= @attribute.class %>" data-item="time">
</div>
<input type="text" value="" class="form-control time js-timepicker <%= @attribute.class %>" data-item="time" <% if @attribute.disabled: %> disabled<% end %>>
</div>

View file

@ -11,18 +11,25 @@ test("DateTime timepicker focuses hours", function(assert) {
model: {
configure_attributes: [
{ name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true },
{ name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: true, disabled: true },
{ name: 'date3', display: 'Date3', tag: 'date', null: true, disabled: true },
]
},
autofocus: true
});
let timepicker = el.find('[data-item=time]')
let timepicker1 = el.find('[data-name=datetime1] [data-item=time]')
//debugger
timepicker.focus()
timepicker1.focus()
setTimeout(function(){ // give it time to apply focus
equal(timepicker[0].selectionStart, 0)
equal(timepicker[0].selectionEnd, 2)
equal(timepicker1[0].selectionStart, 0)
equal(timepicker1[0].selectionEnd, 2)
equal(el.find('[data-name=datetime2] [data-item=date]')[0].disabled, true)
equal(el.find('[data-name=datetime2] [data-item=time]')[0].disabled, true)
equal(el.find('[data-name=date3] [data-item=date]')[0].disabled, true)
done()
}, 100)