[Solved] Umbraco Forms Prevalue value field
# help-with-umbraco
c
V13.2.2 Thought I could set a Forms prevalue source to list some category pages. Managed to do that but is there a way to get the value to be one of the category page's field values? The only things that seem available are Id, Key and Name, which are no good to anyone when you have to send a machine readable value to an end point. We have a special field that holds the categories value for this purpose. Need to be able to use it and it has to be dynamic, i.e. not a hard coded prevalue.
j
Hi @Craig100 you can write your prevalues. So you can get them from an API for example. You could do it that way :D. Create a class and inherit from : FieldPreValueSourceType. Docs are here 🙂 https://docs.umbraco.com/umbraco-forms/developer/extending/adding-a-prevaluesourcetype
c
I'll have a look at that, thanks 🙂
j
No worries, you should in theory be able to read the category values in and thus its dynamic 🙂
c
I've just had a go. And while I purports to be generic, you have to hard code the listing node in, which makes the Source Node selection a bit pointless. Then you have to try to hard code the value field. There's no UI for selecting the listing node then selecting the child node's value field and there's no way to set sort order. However, those concerns aside, I've had some success in that I can create a new Prevalue list showing the child items names but can't quite work out how to select the field I need to populate the value. So I've ended up with this:- https://cdn.discordapp.com/attachments/1222940399790854204/1223258123016474644/image.png?ex=661932e7&is=6606bde7&hm=5aa42d6fb3ffd7edc40078ae6f7c4abde5b80cbad7e3092fc682601a4fdb2e8d&
The code to catch the "value" is this: pv.Value = prevalue.Value("theAlias"); I can't work out the syntax to get it to work 😦
Ignore my last! I got the alias of the field wrong! 🤦 It's now working. However, I would love to be able to sort it alphabetically. I've had a go at it but not sure it's possible. https://cdn.discordapp.com/attachments/1222940399790854204/1223259788788367411/image.png?ex=66193474&is=6606bf74&hm=b7f4385d0c8b7fd177c79e2cfaf11a4149ac4bd9adfb3294505791377ef50ba8&
If only the value field dropdown could be below the Rood Node selection, so it could show all the fields in the child, then it would be perfect! https://cdn.discordapp.com/attachments/1222940399790854204/1223263728229810237/image.png?ex=6619381f&is=6606c31f&hm=6834fa8bce36c750f4da59718cfac6c3efa3e4ff1cdd1fedca638c966a693351&
j
Hi @Craig100 sorry i have just seen this 🙂
I am a bit worried about your approach re: "I've just had a go. And while I purports to be generic, you have to hard code the listing node in, which makes the Source Node selection a bit pointless. Then you have to try to hard code the value field. There's no UI for selecting the listing node then selecting the child node's value field and there's no way to set sort order. However, those concerns aside, I've had some success in that I can create a new Prevalue list showing the child items names but can't quite work out how to select the field I need to populate the value. So I've ended up with this:" And while I purports to be generic, you have to hard code the listing node What do you mean by this? Sounds like you have gone a little wrong. Also have a look at ModelsBuilder and usync. You should not be doing prevalue.Value("theAlias")
c
You're right. Once I change
var preValSourceNode = iPub.Children();
to
var preValSourceNode = iPub.Children<CategoryPage>();
I could then do
pv.Value = prevalue.myProperyValue;
Nice 🙂 You sometimes miss niceties like that in the heat of the struggle 🙂
j
Yea been doing this a while 😉
34 Views