Sha256: 44e716076775f72583d9927a7912bb43a09bfaa1f64ee8b0c1ac3cd9e4a95d63
Contents?: true
Size: 1.14 KB
Versions: 14
Compression:
Stored size: 1.14 KB
Contents
((exports) => { class AutoSelectOptionsFromUrl { constructor(options = {}) { this.$source = options.source; this.$select = options.select; this.sourceToParams = options.sourceToParams; this.run(); } run() { this.$source.on("change", this._onSourceChange.bind(this)); this._onSourceChange(); } _onSourceChange() { const select = this.$select; const params = this.sourceToParams(this.$source); const url = this.$source.data("url"); $.getJSON(url, params, function (data) { select.find("option:not([value=''])").remove(); const selectedValue = select.data("selected"); data.forEach((option) => { let optionElement = $(`<option value="${option.id}">${option.body}</option>`).appendTo(select); if (option.id === selectedValue) { optionElement.attr("selected", true); } }); if (selectedValue) { select.val(selectedValue); } }); } } exports.DecidimAdmin = exports.DecidimAdmin || {}; exports.DecidimAdmin.AutoSelectOptionsFromUrl = AutoSelectOptionsFromUrl; })(window);
Version data entries
14 entries across 14 versions & 1 rubygems