Multi select dropdown in plugin settings?
-
How are you handling the saving code? We recommend using v2 of the admin settings module:
<script> require(['settings'], function(Settings) { Settings.load('quickstart', $('.quickstart-settings')); $('#save').on('click', function() { Settings.save('quickstart', $('.quickstart-settings'), function() { app.alert({ type: 'success', alert_id: 'quickstart-saved', title: 'Settings Saved', message: 'Please reload your NodeBB to apply these settings', clickfn: function() { socket.emit('admin.reload'); } }) }); }); }); </script>
The code there should handle
select
s properly. -
@julian I am using the same exact code. Regular select works fine. The problem is with selects with multiple option.
If I make the select multiple and just pick one option, then I can see the option selected when I come back to the settings page later. If I pick 2 or more and then come back to the page, there is no indication on the UI of which options were selected.
-
Any help? This is the only thing stopping me from finishing the plugin.
-
I reported here please keep in touch for updates
-
Thanks @psychobunny
<div class="form-group col-xs-12"> <label for="categories">Category</label> <select multiple class="form-control" name="categories" title="Categories"> <option value="">Select a category</option> <option value="1">Announcements</option> <option value="2">General Discussion</option> <option value="4">Comments & Feedback</option> <option value="3">Blogs</option> </select> </div>
-
This plugin works for me:
Settings.registerPlugin({ Settings: {}, types: ['selectMultiple'], use: function () { Settings = this; }, set: function (element, value) { if (value.constructor === Array) { for (var val in value) { element.find('option[value=val]').attr("selected",true); } } }, get: function (element, trim, empty) { var value = []; element.find('option:selected').each(function () { value.push($(this).val()); }); return value; } });
With data-type="selectMultiple" added to the select tag.
Copyright © 2024 NodeBB | Contributors