Skip to content

Commit bec73d3

Browse files
authored
fix #21833 - Can't select the TTO or TTR - 10.x (#21994)
* remove calendar button if user doesn't have 'assign' right on sla/ola * fix phpunit tests * Revert "fix phpunit tests" This reverts commit 37e3128. * Revert "remove calendar button if user doesn't have 'assign' right on sla/ola" This reverts commit 43e37ea. * improve date macro instead of changing widget call. All other date widget with `disabled` option won't have a button to choose a date.
1 parent 1890654 commit bec73d3

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

templates/components/form/fields_macros.html.twig

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,21 @@
278278
{% endmacro %}
279279

280280
{% macro flatpickrHtmlInput(name, value, label = '', options = {}) %}
281+
{% set options = {
282+
'readonly': false,
283+
'disabled': false,
284+
}|merge(options) %}
285+
286+
{% set editable = not options.readonly and not options.disabled %}
287+
281288
{% if options.fields_template.isMandatoryField(name) %}
282289
{% set options = {'required': true}|merge(options) %}
283290
{% endif %}
284291

285292
{% if value == 'NULL' %}
286293
{% set value = null %}
287294
{% endif %}
295+
288296
{% if options.checkIsExpired %}
289297
{% if value|date('Y-m-d H:i:s') < "now"|date('Y-m-d H:i:s') %}
290298
{% set class = 'warn' %}
@@ -305,7 +313,7 @@
305313
{{ options.required ? 'required' : '' }}
306314
{{ options.readonly ? 'readonly' : '' }}
307315
{{ options.disabled ? 'disabled' : '' }} />
308-
{% if not options.readonly %}
316+
{% if editable %}
309317
<i class="input-group-text far fa-calendar-alt" data-toggle role="button"></i>
310318
{% endif %}
311319
</div>
@@ -346,35 +354,43 @@
346354
{% endmacro %}
347355

348356
{% macro datetimeField(name, value, label = '', options = {}) %}
349-
{% set options = {'rand': random()}|merge(options) %}
357+
{% set options = {
358+
'rand': random(),
359+
'readonly': false,
360+
'disabled': false,
361+
}|merge(options) %}
350362
{% set options = {'id': name|slug ~ '_' ~ options.rand}|merge(options) %}
363+
351364
{% set locale = get_current_locale() %}
365+
{% set editable = not options.readonly and not options.disabled %}
352366

353367
{% set field %}
354-
{{ _self.flatpickrHtmlInput(name, value, label, options) }}
355-
<script>
356-
$(function() {
357-
$('#{{ options.id }}').flatpickr({
358-
altInput: true,
359-
dateFormat: 'Y-m-d H:i:S',
360-
altFormat: '{{ call('Toolbox::getDateFormat', ['js']) }} H:i:S',
361-
enableTime: true,
362-
wrap: true,
363-
enableSeconds: true,
364-
weekNumbers: true,
365-
time_24hr: true,
366-
allowInput: {{ options.readonly ? 'false' : 'true' }},
367-
clickOpens: {{ options.readonly ? 'false' : 'true' }},
368-
locale: getFlatPickerLocale('{{ locale['language'] }}', '{{ locale['region'] }}'),
369-
onClose(dates, currentdatestring, picker) {
370-
picker.setDate(picker.altInput.value, true, picker.config.altFormat)
371-
},
372-
plugins: [
373-
CustomFlatpickrButtons()
374-
]
375-
});
376-
});
377-
</script>
368+
{{ _self.flatpickrHtmlInput(name, value, label, options) }}
369+
{% if editable %}
370+
<script>
371+
$(function () {
372+
$('#{{ options.id }}').flatpickr({
373+
altInput: true,
374+
dateFormat: 'Y-m-d H:i:S',
375+
altFormat: '{{ call('Toolbox::getDateFormat', ['js']) }} H:i:S',
376+
enableTime: true,
377+
wrap: true,
378+
enableSeconds: true,
379+
weekNumbers: true,
380+
time_24hr: true,
381+
allowInput: {{ editable ? 'true' : 'false' }},
382+
clickOpens: {{ editable ? 'true' : 'false' }},
383+
locale: getFlatPickerLocale('{{ locale['language'] }}', '{{ locale['region'] }}'),
384+
onClose(dates, currentdatestring, picker) {
385+
picker.setDate(picker.altInput.value, true, picker.config.altFormat)
386+
},
387+
plugins: [
388+
CustomFlatpickrButtons()
389+
]
390+
});
391+
});
392+
</script>
393+
{% endif %}
378394
{% endset %}
379395

380396
{{ _self.field(name, field, label, options) }}

0 commit comments

Comments
 (0)