I'm trying to populate an HTML dropdown (select, rather) with all prevalues from the dropdown datatype in Umbraco and then set the selected prevalue when the document loads.
I've got it working, but the dropdown selects the wrong value even though the right option tag is set to selected.
As you can see, the value of the selected option is "3 - 6 timer", but on the page it displays the "6 timer" option as selected?
My Razor looks like this:
<select data-bind="selectedOptions: selectedLength"> @{ // Get prevalues from the length dropdown datatype XPathNodeIterator lengthPreValueRootElementIterator = umbraco.library.GetPreValues(1102); lengthPreValueRootElementIterator.MoveNext(); //move to first preValueIterator = lengthPreValueRootElementIterator.Current.SelectChildren("preValue", "");
The only thing I can come up with in this, is that "6 timer" is a part of the "3 - 6 timer" string, but it still doesn't make any sense to me. If I choose e.g. 3 - 4 timer in the backend, it will display "4 timer" in the dropdown menu on the frontend, even though the selected option says value="3 - 4 timer"
Weird dropdown behavior: displays the wrong value
Hi all,
I'm trying to populate an HTML dropdown (select, rather) with all prevalues from the dropdown datatype in Umbraco and then set the selected prevalue when the document loads.
I've got it working, but the dropdown selects the wrong value even though the right option tag is set to selected.
The options gets populated like this in HTML:
.....
<option value="6 timer">6 timer</option>
As you can see, the value of the selected option is "3 - 6 timer", but on the page it displays the "6 timer" option as selected?
My Razor looks like this:
<select data-bind="selectedOptions: selectedLength">
@{
// Get prevalues from the length dropdown datatype
XPathNodeIterator lengthPreValueRootElementIterator = umbraco.library.GetPreValues(1102);
lengthPreValueRootElementIterator.MoveNext(); //move to first
preValueIterator = lengthPreValueRootElementIterator.Current.SelectChildren("preValue", "");
List<string> umbPreValues = new List<string>();
while(preValueIterator.MoveNext())
{
umbPreValues.Add(preValueIterator.Current.Value);
}
foreach(string preValue in umbPreValues)
{
if(preValue.Equals(node.varighed))
{
<option class="initial" selected="selected" value='@node.varighed'>@node.varighed</option>
}
else
{
<option value='@preValue'>@preValue</option>
}
}
}
</select>
I must admit that I fail to see the flaw in this - simply because the selected value is set to the right prevalue in the HTML source.
And it's not because the "6 timer" is the last prevalue in the list. It goes up to "10 timer" (timer = hours in danish)
Any help on this would be greatly appreciated! :)
Thanks in advance.
All the best,
Bo
The only thing I can come up with in this, is that "6 timer" is a part of the "3 - 6 timer" string, but it still doesn't make any sense to me. If I choose e.g. 3 - 4 timer in the backend, it will display "4 timer" in the dropdown menu on the frontend, even though the selected option says value="3 - 4 timer"
I don't get it ;-)
Alright, with strange issues comes strange fixes - all of sudden it started to work today ;-) Wish I could explain what I did to make it work.
is working on a reply...