Sorry if this is not the correct way to submit changes, but have run into an issue and found what I believe is the correct fix.
(nb:Tried to select the component but couldnt, so had to put in title)
When using the CascadingDropDown I needed to add some custom attributes to each listItem
To do this I decided to pass back JSON data in the items value property.
This all works fine, but then when trying to get the knownCategoryValues I run into problems if I use the built in ParseKnownCategoryValuesString.
Looking at the source, this is because the string is being split on ; and then each item on :
Where the value of my drop down contains my JSON data this fails for the following knownCategoryValues string:
Media:1;Client:{"Name":"ABC","Id":123,"Code":"ABC","Currency":"EUR"};
I created a slightly modified version of this that handles this scenario, but shoudl not affect others where we look for the first occurance of the : seperator and parse that way. The modified lines are marked. I also assume this would break if any of the drop down values contained a colon.
public static System.Collections.Specialized.StringDictionary ParseKnownCategoryValuesString(string KnownCategoryValues)
{
// Validate parameters
if (null == KnownCategoryValues)
{
throw new ArgumentNullException("knownCategoryValues");
}
System.Collections.Specialized.StringDictionary dictionary = new System.Collections.Specialized.StringDictionary();
if (null != KnownCategoryValues)
{
// Split into category/value pairs
foreach (string knownCategoryValue in KnownCategoryValues.Split(';'))
{
// Split into category and value
string[] knownCategoryValuePair = knownCategoryValue.Split(':');
//MODIFIED:check for exactly 2 items breaks if value contains our : seperator
if (knownCategoryValuePair.Length>=2)
{
// Add the pair to the dictionary
//MODIFIED:changed to extract value after the 1st : so wont get confused if value conatins a colon
dictionary.Add(knownCategoryValuePair[0].ToLowerInvariant(),
knownCategoryValue.Substring(knownCategoryValue.IndexOf(":") + 1));
}
}
}
return dictionary;
}
If there is a different / better way of submitting potential bugs / fixes please let me know
Thanks
Comments: Thank you for your suggestion! We will keep it in mind during our future work.
(nb:Tried to select the component but couldnt, so had to put in title)
When using the CascadingDropDown I needed to add some custom attributes to each listItem
To do this I decided to pass back JSON data in the items value property.
This all works fine, but then when trying to get the knownCategoryValues I run into problems if I use the built in ParseKnownCategoryValuesString.
Looking at the source, this is because the string is being split on ; and then each item on :
Where the value of my drop down contains my JSON data this fails for the following knownCategoryValues string:
Media:1;Client:{"Name":"ABC","Id":123,"Code":"ABC","Currency":"EUR"};
I created a slightly modified version of this that handles this scenario, but shoudl not affect others where we look for the first occurance of the : seperator and parse that way. The modified lines are marked. I also assume this would break if any of the drop down values contained a colon.
public static System.Collections.Specialized.StringDictionary ParseKnownCategoryValuesString(string KnownCategoryValues)
{
// Validate parameters
if (null == KnownCategoryValues)
{
throw new ArgumentNullException("knownCategoryValues");
}
System.Collections.Specialized.StringDictionary dictionary = new System.Collections.Specialized.StringDictionary();
if (null != KnownCategoryValues)
{
// Split into category/value pairs
foreach (string knownCategoryValue in KnownCategoryValues.Split(';'))
{
// Split into category and value
string[] knownCategoryValuePair = knownCategoryValue.Split(':');
//MODIFIED:check for exactly 2 items breaks if value contains our : seperator
if (knownCategoryValuePair.Length>=2)
{
// Add the pair to the dictionary
//MODIFIED:changed to extract value after the 1st : so wont get confused if value conatins a colon
dictionary.Add(knownCategoryValuePair[0].ToLowerInvariant(),
knownCategoryValue.Substring(knownCategoryValue.IndexOf(":") + 1));
}
}
}
return dictionary;
}
If there is a different / better way of submitting potential bugs / fixes please let me know
Thanks
Comments: Thank you for your suggestion! We will keep it in mind during our future work.