Skip to content

Commit

Permalink
Fixes #27903 - Do not init template-form-elements
Browse files Browse the repository at this point in the history
fixes problem with not initialized counter and byte-size input elements
within dynamically added volumes of compute-resources in host-create
  • Loading branch information
m-bucher committed Oct 2, 2019
1 parent 9a92ed9 commit 5dd656e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/lookup_keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function add_child_node(item) {
$('a[rel="popover"]').popover();
$('a[rel="twipsy"]').tooltip();
activate_select2($(field).not('.matcher_key'));
tfm.numFields.initAll(field);
return new_id;
}

Expand Down
29 changes: 22 additions & 7 deletions webpack/assets/javascripts/jquery.ui.custom_spinners.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,30 @@ $(() => {
});
});

export function initAll() {
initByte();
initCounter();
export function initAll(selection = null) {
// might be called with Event-argument, if used as EventHandler
if (
selection !== null &&
typeof selection === 'object' &&
(selection.hasOwnProperty('originalEvent') ||
selection.constructor === $.Event)
) {
selection = null;
}
initByte(selection);
initCounter(selection);
}

export function initCounter() {
$('input.counter_spinner').each(function() {
export function initCounter(selection = null) {
$('input.counter_spinner', selection).each(function() {
const field = $(this);
const errorMessage = field.closest('.form-group').find('.maximum-limit');
let min = field.data('min');
min = typeof min === 'number' ? min : 1;

// Do not initialize form_templates
if (field.parents('.form_template').length > 0) return;

field.limitedSpinner({
softMaximum: field.data('softMax'),
errorTarget: errorMessage,
Expand All @@ -135,12 +147,15 @@ export function initCounter() {
});
}

export function initByte() {
$('input.byte_spinner').each(function() {
export function initByte(selection = null) {
$('input.byte_spinner', selection).each(function() {
const field = $(this);
const errorMessage = field.closest('.form-group').find('.maximum-limit');
const valueTarget = field.closest('.form-group').find('.real-hidden-value');

// Do not initialize form_templates
if (field.parents('.form_template').length > 0) return;

field.byteSpinner({
valueTarget,
softMaximum: field.data('softMax'),
Expand Down

0 comments on commit 5dd656e

Please sign in to comment.