From 12055f3762ceaf631690b6f5857d5e7dd87e7dcf Mon Sep 17 00:00:00 2001 From: Markus Bucher Date: Fri, 20 Sep 2019 10:28:15 +0200 Subject: [PATCH] Fixes #27903 - Do not init template-form-elements fixes problem with not initialized counter and byte-size input elements within dynamically added volumes of compute-resources in host-create --- app/assets/javascripts/lookup_keys.js | 1 + .../javascripts/jquery.ui.custom_spinners.js | 27 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/lookup_keys.js b/app/assets/javascripts/lookup_keys.js index 329d94bf4267..e9c7bb24df11 100644 --- a/app/assets/javascripts/lookup_keys.js +++ b/app/assets/javascripts/lookup_keys.js @@ -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; } diff --git a/webpack/assets/javascripts/jquery.ui.custom_spinners.js b/webpack/assets/javascripts/jquery.ui.custom_spinners.js index ae784ab3f612..789fc094d19c 100644 --- a/webpack/assets/javascripts/jquery.ui.custom_spinners.js +++ b/webpack/assets/javascripts/jquery.ui.custom_spinners.js @@ -105,16 +105,26 @@ $(() => { }); }); -export function initAll() { - initByte(); - initCounter(); +export function initAll(selection = null) { + // might be called with Event-argument, if used as EventHandler + if ( + typeof selection === 'object' && + selection.hasOwnProperty('originalEvent') + ) { + 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'); + // Do not initialize form_templates + if (field.parents('.form_template').length > 0) return; + field.limitedSpinner({ softMaximum: field.data('softMax'), errorTarget: errorMessage, @@ -132,12 +142,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'),