Skip to content

Commit

Permalink
Schedule form: Limit numeric inputs to min/max
Browse files Browse the repository at this point in the history
  • Loading branch information
maurofmferrao committed Dec 16, 2024
1 parent 30eef91 commit e0d5125
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
17 changes: 17 additions & 0 deletions ui/src/core/xibo-cms.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,23 @@ function XiboInitialise(scope, options) {
}
});

// Prevent manual numbers input outside of min/max
$(
scope + ' input[type="number"][min], ' +
scope + ' input[type="number"][max]',
).each((_idx, input) => {
const $input = $(input);
const max = $input.attr('max');
const min = $input.attr('min');

$input.on('blur', () => {
(max && $input.val() > max) &&
($input.val(max).trigger('change'));
(min && $input.val() < min) &&
($input.val(min).trigger('change'));
});
});

// Links that just need to be submitted as forms
$(scope + ' .XiboAjaxSubmit').click(function(){

Expand Down
4 changes: 2 additions & 2 deletions views/forms.twig
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@
</div>
{% endmacro %}

{% macro number(name, title, value, helpText, groupClass, validation, accessKey, maxNumber) %}
{% macro number(name, title, value, helpText, groupClass, validation, accessKey, maxNumber, minNumber) %}
<div class="form-group row {{ groupClass }}">
<label class="col-sm-2 control-label" for="{{ name }}" accesskey="{{ accessKey }}">{{ title }}</label>
<div class="col-sm-10">
<input class="form-control" name="{{ name }}" {% if maxNumber %}max="{{maxNumber}}" {% endif %}type="number" id="{{ name }}" value="{{ value }}" {{ validation }} />
<input class="form-control" name="{{ name }}" {% if maxNumber != undefined %}max="{{maxNumber}}" {% endif %}{% if minNumber != undefined %}min="{{minNumber}}" {% endif %}type="number" id="{{ name }}" value="{{ value }}" {{ validation }} />
<small class="form-text text-muted">{{ helpText }}</small>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions views/inline.twig
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
</div>
{% endmacro %}

{% macro number(name, title, value, helpText, groupClass, validation, accessKey, maxNumber) %}
{% macro number(name, title, value, helpText, groupClass, validation, accessKey, maxNumber, minNumber) %}
<div class="form-group mr-1 mb-1 {{ groupClass }}">
<label class="control-label mr-1" title="{{ helpText }}" for="{{ name }}" accesskey="{{ accessKey }}">{{ title }}</label>
<input class="form-control" name="{{ name }}" {% if maxNumber %}max="{{maxNumber}}" {% endif %}type="number" id="{{ name }}" value="{{ value }}" {{ validation }} />
<input class="form-control" name="{{ name }}" {% if maxNumber %}max="{{maxNumber}}" {% endif %}{% if minNumber %}min="{{minNumber}}" {% endif %}type="number" id="{{ name }}" value="{{ value }}" {{ validation }} />
</div>
{% endmacro %}

Expand Down
6 changes: 3 additions & 3 deletions views/schedule-form-add.twig
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@

{% set title %}{% trans "Display Order" %}{% endset %}
{% set helpText %}{% trans "Please select the order this event should appear in relation to others when there is more than one event scheduled" %}{% endset %}
{{ forms.number("displayOrder", title, "", helpText, 'displayOrder-control') }}
{{ forms.number("displayOrder", title, "", helpText, 'displayOrder-control', "", "", "", "0") }}

{% set title %}{% trans "Priority" %}{% endset %}
{% set helpText %}{% trans "Sets the event priority - events with the highest priority play in preference to lower priority events." %}{% endset %}
{{ forms.number("isPriority", title, "", helpText, 'priority-control') }}
{{ forms.number("isPriority", title, "", helpText, 'priority-control', "", "", "", "0") }}

{% set title %}{% trans "Maximum plays per hour" %}{% endset %}
{% set helpText %}{% trans "Limit the number of times this event will play per hour on each display. For unlimited plays set to 0." %}{{ forms.playerCompat("R308", "", "", "", "R306", "") }}{% endset %}
Expand Down Expand Up @@ -297,7 +297,7 @@
<label class="col-sm-2 control-label" for="recurrenceDetail">{{ title }}</label>
<div class="col-sm-10">
<div class="input-group">
<input class="form-control" name="recurrenceDetail" type="number" id="recurrenceDetail" value="{{ event.recurrenceDetail }}" />
<input class="form-control" name="recurrenceDetail" min="0" type="number" id="recurrenceDetail" value="{{ event.recurrenceDetail }}" />
<div class="input-group-append">
<span class="input-group-text input-group-addon"></span>
</div>
Expand Down
6 changes: 3 additions & 3 deletions views/schedule-form-edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@

{% set title %}{% trans "Display Order" %}{% endset %}
{% set helpText %}{% trans "Please select the order this event should appear in relation to others when there is more than one event scheduled" %}{% endset %}
{{ forms.number("displayOrder", title, event.displayOrder, helpText, 'displayOrder-control') }}
{{ forms.number("displayOrder", title, event.displayOrder, helpText, 'displayOrder-control', "", "", "", "0") }}

{% set title %}{% trans "Priority" %}{% endset %}
{% set helpText %}{% trans "Sets the event priority - events with the highest priority play in preference to lower priority events." %}{% endset %}
{{ forms.number("isPriority", title, event.isPriority, helpText, 'priority-control') }}
{{ forms.number("isPriority", title, event.isPriority, helpText, 'priority-control', "", "", "", "0") }}

{% set title %}{% trans "Maximum plays per hour" %}{% endset %}
{% set helpText %}{% trans "Limit the number of times this event will play per hour on each display. For unlimited plays set to 0." %}{{ forms.playerCompat("R308", "", "", "", "R306", "") }}{% endset %}
Expand Down Expand Up @@ -311,7 +311,7 @@
<label class="col-sm-2 control-label" for="recurrenceDetail">{{ title }}</label>
<div class="col-sm-10">
<div class="input-group">
<input class="form-control" name="recurrenceDetail" type="number" id="recurrenceDetail" value="{{ event.recurrenceDetail }}" />
<input class="form-control" name="recurrenceDetail" min="0" type="number" id="recurrenceDetail" value="{{ event.recurrenceDetail }}" />
<div class="input-group-append">
<span class="input-group-text input-group-addon"></span>
</div>
Expand Down

0 comments on commit e0d5125

Please sign in to comment.