mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixing taxonomy terms picker with spaces and commas
This commit is contained in:
@@ -2,26 +2,6 @@
|
||||
|
||||
/* Helper functions
|
||||
**********************************************************************/
|
||||
var parseTerms = function (text) {
|
||||
var tuples = text.split(",");
|
||||
var terms = [];
|
||||
|
||||
for (var i = 0; i < tuples.length; i++) {
|
||||
var tuple = tuples[i].split("\t");
|
||||
var value = parseInt(tuple[1]);
|
||||
var levels = parseInt(tuple[2]);
|
||||
var tag = {
|
||||
label: tuple[0],
|
||||
value: value,
|
||||
levels: !isNaN(levels) ? levels : 0,
|
||||
disabled: tuple[3] == "True"
|
||||
};
|
||||
terms.push(tag);
|
||||
}
|
||||
|
||||
return terms;
|
||||
};
|
||||
|
||||
var addTag = function ($plugin, label) {
|
||||
$plugin.tagit("add", label);
|
||||
};
|
||||
@@ -168,13 +148,13 @@
|
||||
/* Initialization
|
||||
**********************************************************************/
|
||||
$(".terms-editor").each(function () {
|
||||
var allTerms = parseTerms($(this).data("all-terms"));
|
||||
var selectedTerms = parseTerms($(this).data("selected-terms"));
|
||||
var allTerms = $(this).data("all-terms");
|
||||
var selectedTerms = $(this).data("selected-terms");
|
||||
|
||||
var $tagit = $("> ul", this).tagit({
|
||||
tagSource: allTerms,
|
||||
initialTags: selectedTerms,
|
||||
triggerKeys: ['enter', 'comma', 'tab'],
|
||||
triggerKeys: ['enter', 'tab'], // default is ['enter', 'space', 'comma', 'tab'] but we remove comma and space to allow them in the terms
|
||||
allowNewTags: $(this).data("allow-new-terms"),
|
||||
tagsChanged: onTagsChanged,
|
||||
caseSensitive: false,
|
||||
|
@@ -26,8 +26,8 @@
|
||||
}
|
||||
}
|
||||
@{
|
||||
var allTerms = string.Join(",", Model.Terms.Select(x => string.Format("{0}\t{1}\t{2}\t{3}", x.Name, x.Id, x.GetLevels(), IsTermDisabled(x))));
|
||||
var selectedTerms = string.Join(",", Model.Terms.Where(x => x.IsChecked).Select(x => string.Format("{0}\t{1}", x.Name, x.Id)));
|
||||
var allTerms = Newtonsoft.Json.JsonConvert.SerializeObject(Model.Terms.Select(x => new { label = x.Name, value = x.Id, levels = x.GetLevels(), disabled = IsTermDisabled(x)}));
|
||||
var selectedTerms = Newtonsoft.Json.JsonConvert.SerializeObject(Model.Terms.Where(x => x.IsChecked).Select(x => new { label = x.Name, value = x.Id, levels = 0, disabled = true }));
|
||||
}
|
||||
<fieldset class="taxonomy-wrapper" data-name-prefix="@Html.FieldNameFor(m => m)" data-id-prefix="@Html.FieldIdFor(m => m)">
|
||||
<legend @if(Model.Settings.Required) { <text>class="required"</text> }>@Model.DisplayName.CamelFriendly()</legend>
|
||||
|
Reference in New Issue
Block a user