JS cleanup.

This commit is contained in:
Pēteris Caune 2020-03-09 10:16:39 +02:00
parent 3e25e5c242
commit 6147451851
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
2 changed files with 10 additions and 12 deletions

View File

@ -7,7 +7,10 @@ $(function () {
$("#update-name-form").attr("action", url); $("#update-name-form").attr("action", url);
$("#update-name-input").val(this.dataset.name); $("#update-name-input").val(this.dataset.name);
var tagsSelectize = document.getElementById("update-tags-input").selectize;
tagsSelectize.setValue(this.dataset.tags.split(" ")); tagsSelectize.setValue(this.dataset.tags.split(" "));
$("#update-desc-input").val(this.dataset.desc); $("#update-desc-input").val(this.dataset.desc);
$('#update-name-modal').modal("show"); $('#update-name-modal').modal("show");
$("#update-name-input").focus(); $("#update-name-input").focus();
@ -234,6 +237,10 @@ $(function () {
}); });
// Configure Selectize for entering tags // Configure Selectize for entering tags
function divToOption() {
return {value: this.textContent};
}
$("#update-tags-input").selectize({ $("#update-tags-input").selectize({
create: true, create: true,
createOnBlur: true, createOnBlur: true,
@ -241,12 +248,8 @@ $(function () {
labelField: "value", labelField: "value",
searchField: ["value"], searchField: ["value"],
hideSelected: true, hideSelected: true,
highlight: false highlight: false,
}); options: $("#my-checks-tags div").map(divToOption).get()
var tagsSelectize = document.getElementById("update-tags-input").selectize;
$("#my-checks-tags div").each(function(idx, el) {
tagsSelectize.addOption({value: el.textContent});
}); });
}); });

View File

@ -7,12 +7,7 @@ $(function () {
}); });
// Configure Selectize for entering tags // Configure Selectize for entering tags
var options = [];
var allTags = $("#update-tags-input").data("all-tags").split(" "); var allTags = $("#update-tags-input").data("all-tags").split(" ");
for (var i=0, tag; tag = allTags[i]; i++) {
options.push({value: tag});
}
$("#update-tags-input").selectize({ $("#update-tags-input").selectize({
create: true, create: true,
createOnBlur: true, createOnBlur: true,
@ -21,7 +16,7 @@ $(function () {
searchField: ["value"], searchField: ["value"],
hideSelected: true, hideSelected: true,
highlight: false, highlight: false,
options: options options: allTags.map(function(tag) { return {value: tag} })
}); });
$("#new-check-alert a").click(function() { $("#new-check-alert a").click(function() {