diff --git a/CHANGELOG.md b/CHANGELOG.md index 184345281..b98eaa500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,3 +101,4 @@ Branch CRUD-Init - css: add an extra space around choices expanded widget - add Tabs parametric feature to easily render tabs panels - css: add a margin on the button "delete entry" in collection +- module `show_hide`: add the possibility to launch a show hide manually and not on page loading. Useful when show/hide occurs in collection. diff --git a/Resources/public/modules/show_hide/show_hide.js b/Resources/public/modules/show_hide/show_hide.js index a634df212..f22064433 100644 --- a/Resources/public/modules/show_hide/show_hide.js +++ b/Resources/public/modules/show_hide/show_hide.js @@ -23,9 +23,14 @@ var ShowHide = function(options) { container = typeof options.container[Symbol.iterator] === "function" ? options.container : [ options.container ], is_shown = true, event_name = 'event_name' in options ? options.event_name : 'change', - container_content = []; - - window.addEventListener('load', function(event) { + container_content = [], + debug = 'debug' in options ? options.debug : false, + load_event = 'load_event' in options ? options.load_event : 'load'; + + var bootstrap = function(event) { + if (debug) { + console.log('debug is activated on this show-hide', this); + } // keep the content in memory for (let c of container.values()) { let contents = []; @@ -39,6 +44,9 @@ var ShowHide = function(options) { for (let f of froms.values()) { let inputs = f.querySelectorAll('input'); for (let input of inputs.values()) { + if (debug) { + console.log('attaching event to input', input); + } input.addEventListener(event_name, function(e) { onChange(e); }); @@ -46,8 +54,8 @@ var ShowHide = function(options) { } // first launch of the show/hide - onChange(event); - }); + onChange(event); + }; var onChange = function (event) { @@ -77,6 +85,13 @@ var ShowHide = function(options) { } }; + + + if (load_event !== null) { + window.addEventListener('load', bootstrap); + } else { + bootstrap(null); + } }; export {ShowHide};