-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow setting select data without losing the current selection. #1497
Comments
In 4.3.10 I added
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link href="../metro/css/metro-all.css?ver=@@b-version" rel="stylesheet">
<title>Select set data test - Metro 4 :: Popular HTML, CSS and JS library</title>
</head>
<body class="m4-cloak">
<div class="container">
<h1>Select set data test page</h1>
<div>
<button class="button" onclick="loadData()">Load data</button>
</div>
<div class="row">
<div class="cell-md-6">
<select id="sel1" data-role="select">
<option value="1">Item 1</option>
<option value="2" selected>Item 2</option>
<option value="3">Item 3</option>
</select>
</div>
<div class="cell-md-6">
<select id="sel2" data-role="select" multiple>
<option value="1">Item 1</option>
<option value="2" selected>Item 2</option>
<option value="3" selected>Item 3</option>
</select>
</div>
</div>
</div>
<script src="../metro/js/metro.js?ver=@@b-version"></script>
<script>
function loadData(){
var data = {
1: "Item 1",
"2": "Item 2",
3: "Item 3",
4: "Item 4",
5: "Item 5",
};
var selected1 = [2];
var selected2 = [2, 3, 4];
Metro.getPlugin("#sel1", "select").data(data, selected1);
Metro.getPlugin("#sel2", "select").data(data, selected2);
}
</script>
</body>
</html> |
…d argument. Must be a `string` or `array`, issue #1497
Thank you very much! 😊 I will update my version and try this out, when I've got time. Also, I've send you a donation. Hope it helps you! 💸 |
Thank you for your donation ❤️. Could you clarify the details of the donation, I can not find the transaction. Thanks you. |
I've used the SEPA EURO bank account from your support page (GB61CLJU00997180121989). It should be transferred in a couple of days. |
Thank you my friend ❤️ |
…d argument. Must be a `string` or `array`, issue #1497
First of all, I want to thank you for your awesome work. MetroUI has made my life easier for a few years now. The current version is a blast and it looks gorgeous.
Now to my suggestion: I recently built upon the Ajax Select sample to create a server-side suggestion list, i.e. the user types in some string and the server returns a JSON-list of suggestions using AJAX. I found this a little bit cumbersome, since while it is possible to set the select options using
.data(...)
, it completely rebuilds the options list, which also removes the previously selected items (in case of amultiple
select).I came up with a solution that caches the current selection manually:
There are two things that I think would greatly improve the select control. First of all (and my main point, as the title suggests), I would love to be able to set the response and keep the currently selected options. The select control already stores them, but is getting reset with setting the data. Maybe a boolean flag could be added, which already reduces the code to something like this:
Second, I think it would be nice to have some built-in events to hook filtering (e.g.
onFiltering
which hooks into the filter-controlinput
event andonFiltered
, which could be executed, after the filtered results are shown). This would further simplify the code above:Thanks in advance and keep up your work! 👍
The text was updated successfully, but these errors were encountered: