parent
42b08f9bcd
commit
ba3b108239
|
@ -17,7 +17,7 @@
|
||||||
err.show();
|
err.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
$.fn.selectSelector = function(source, name, select) {
|
$.fn.selectSelector = function(source, select) {
|
||||||
return this.each(function() {
|
return this.each(function() {
|
||||||
var selector = $(this),
|
var selector = $(this),
|
||||||
input = $('input[type=text]', this);
|
input = $('input[type=text]', this);
|
||||||
|
@ -25,33 +25,28 @@
|
||||||
selector.click(function() { input.focus(); })
|
selector.click(function() { input.focus(); })
|
||||||
.delegate('.badge a', 'click', function() {
|
.delegate('.badge a', 'click', function() {
|
||||||
var id = $(this).parent().data("id");
|
var id = $(this).parent().data("id");
|
||||||
for (var i = 0; i < source.length; i++) {
|
select.find("option[value=" + id + "]").attr("selected", false)
|
||||||
if (source[i].id == id) {
|
|
||||||
source[i].selected = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
select.find("option[value=" + id + "]").attr("selected", null)
|
|
||||||
recreate();
|
recreate();
|
||||||
});
|
});
|
||||||
|
|
||||||
function addTag(item) {
|
function addTag(id, text) {
|
||||||
var tag = $('<span class="badge badge-pill badge-primary"/>')
|
$('<span class="badge badge-pill badge-primary"/>')
|
||||||
.text(item.toString() + ' ')
|
.text(text + ' ')
|
||||||
.data("id", item.id)
|
.data("id", id)
|
||||||
.append('<a>x</a>')
|
.append('<a>x</a>')
|
||||||
.insertBefore(input);
|
.insertBefore(input);
|
||||||
input.attr("placeholder", null);
|
input.attr("placeholder", null);
|
||||||
select.find("option[value=" + item.id + "]").attr("selected", "selected")
|
select.find("option[value='" + id + "']").attr("selected", "selected")
|
||||||
hide_error(input);
|
hide_error(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
function recreate() {
|
function recreate() {
|
||||||
selector.find("span").remove();
|
selector.find("span").remove();
|
||||||
for (var i = 0; i < source.length; i++) {
|
select.find("option").each(function() {
|
||||||
if (source[i].selected) {
|
if (this.hasAttribute("selected")) {
|
||||||
addTag(source[i]);
|
addTag(this.getAttribute("value"), this.innerText);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
recreate();
|
recreate();
|
||||||
|
|
||||||
|
@ -70,7 +65,7 @@
|
||||||
minLength: 0,
|
minLength: 0,
|
||||||
source: source,
|
source: source,
|
||||||
select: function(event, ui) {
|
select: function(event, ui) {
|
||||||
addTag(ui.item);
|
addTag(ui.item.id, ui.item.toString());
|
||||||
input.val("");
|
input.val("");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -253,8 +248,7 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(options);
|
ele.selectSelector(options, sel);
|
||||||
ele.selectSelector(options, sel.attr("name"), sel);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".metapackage_selector").each(function() {
|
$(".metapackage_selector").each(function() {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
{% macro form_scripts() -%}
|
{% macro form_scripts() -%}
|
||||||
<link href="/static/jquery-ui.min.css" rel="stylesheet" type="text/css">
|
<link href="/static/jquery-ui.min.css" rel="stylesheet" type="text/css">
|
||||||
<script src="/static/jquery-ui.min.js"></script>
|
<script src="/static/jquery-ui.min.js"></script>
|
||||||
<script src="/static/tagselector.js"></script>
|
<script src="/static/tagselector.js?v=2"></script>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro package_lists() -%}
|
{% macro package_lists() -%}
|
||||||
|
|
Loading…
Reference in New Issue