I'm using a prevalue source in an Umbraco Form to render a list of options from a db table. I've noticed in the html markup that the Value Column is placed in both the list value and the label like so:
I'd expect the input value to be the Key Column and the label text to be the Value Column. So it appears that the Key Column is completely ignored when rendering the list. Has anyone else encountered this? Am I doing something wrong or is there some other way to retrieve the Key Column value of the selected list item?
NOTE: tried to post this under Umbraco Forms, but the category field appears to have disappeared.
Ok I found out how to fix this. Realised the markup is controlled by the partial view in Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.RadioButtonList.cshtml and DropDownList.cshtml.
HOWEVER: this is great for field values from a db table, but won't work for fields where you've specified a hardcoded list of prevalues. Therefore to handle both scenarios the above line becomes:
So if the Id is 0, it uses the string value as before (hardcoded prevalue ids are always zero), otherwise it uses the Id from prevalue source Id field.
The caveat here is that this solution assumes you aren't populating any prevalues with a legitimate Id of 0.
Umbraco Forms PreValue source issue
I'm using a prevalue source in an Umbraco Form to render a list of options from a db table. I've noticed in the html markup that the Value Column is placed in both the list value and the label like so:
I'd expect the input value to be the Key Column and the label text to be the Value Column. So it appears that the Key Column is completely ignored when rendering the list. Has anyone else encountered this? Am I doing something wrong or is there some other way to retrieve the Key Column value of the selected list item?
NOTE: tried to post this under Umbraco Forms, but the category field appears to have disappeared.
Ok I found out how to fix this. Realised the markup is controlled by the partial view in Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.RadioButtonList.cshtml and DropDownList.cshtml.
So the line that reads:
needs to read:
HOWEVER: this is great for field values from a db table, but won't work for fields where you've specified a hardcoded list of prevalues. Therefore to handle both scenarios the above line becomes:
So if the Id is 0, it uses the string value as before (hardcoded prevalue ids are always zero), otherwise it uses the Id from prevalue source Id field.
The caveat here is that this solution assumes you aren't populating any prevalues with a legitimate Id of 0.
is working on a reply...