mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 17:08:47 +08:00
Prevent TermsFilter from having to deal with empty strings (#8727)
* Prevent TermsFilter from having to deal with empty strings: filter them out before parsing them to int in form, convert taxonomies to OptionGroups rather than options with no value * Update src/Orchard.Web/Modules/Orchard.Taxonomies/Projections/TermsFilter.cs Co-authored-by: Sébastien Ros <sebastienros@gmail.com> --------- Co-authored-by: Sébastien Ros <sebastienros@gmail.com>
This commit is contained in:
parent
9644ceda1f
commit
e013e00dd4
@ -36,7 +36,10 @@ namespace Orchard.Taxonomies.Projections {
|
||||
var termIds = (string)context.State.TermIds;
|
||||
|
||||
if (!String.IsNullOrEmpty(termIds)) {
|
||||
var ids = termIds.Split(new[] { ',' }).Select(Int32.Parse).ToArray();
|
||||
var ids = termIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
// Int32.Parse throws for empty strings
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x))
|
||||
.Select(Int32.Parse).ToArray();
|
||||
|
||||
if (ids.Length == 0) {
|
||||
return;
|
||||
|
@ -57,7 +57,8 @@ namespace Orchard.Taxonomies.Projections {
|
||||
);
|
||||
|
||||
foreach (var taxonomy in _taxonomyService.GetTaxonomies()) {
|
||||
f._Terms.Add(new SelectListItem { Value = String.Empty, Text = taxonomy.Name });
|
||||
var tGroup = new SelectListGroup { Name = taxonomy.Name };
|
||||
f._Terms.Add(tGroup);
|
||||
foreach (var term in _taxonomyService.GetTerms(taxonomy.Id)) {
|
||||
var gap = new string('-', term.GetLevels());
|
||||
|
||||
@ -65,7 +66,11 @@ namespace Orchard.Taxonomies.Projections {
|
||||
gap += " ";
|
||||
}
|
||||
|
||||
f._Terms.Add(new SelectListItem { Value = term.Id.ToString(), Text = gap + term.Name });
|
||||
f._Terms.Add(new SelectListItem {
|
||||
Value = term.Id.ToString(),
|
||||
Text = gap + term.Name,
|
||||
Group = tGroup
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user