Set a checkbox list item as checked using Action Handler
Another newbie question...
I'm trying to create an action handler that sets a particular checkbox list item as checked when a new page is created. All the available doc types have the checkbox list - i've got this working for a text box (setting a default line of text) but am struggling to get an object that represents my checkboxlist.
This is how i'm trying to get the list:-
umbraco.cms.businesslogic.property.Property p = documentObject.getProperty("memCats");
I was thinking i need to cast it somehow or is it just case of setting the value of p to be a string with the item text in it ie:-
According to the source it is mapping on text values so it should be working like you described. Allthough I see that a comma is always added after the value as you can see in the code snippet below. so maybe you can try p.Value = "option1,"
[code]_text += li.Value + ",";[/code]
If you are useing Action Handlers you must save the document yourself to see the changes (it is a post save).
In Umbraco V4 Events are the way to go to hook into actions. Checkout chapter 6 of this book how to wire it up. I have a few examples on my weblog also. The event you need is Document.BeforeSave
Set a checkbox list item as checked using Action Handler
Another newbie question...
I'm trying to create an action handler that sets a particular checkbox list item as checked when a new page is created. All the available doc types have the checkbox list - i've got this working for a text box (setting a default line of text) but am struggling to get an object that represents my checkboxlist.
This is how i'm trying to get the list:-
umbraco.cms.businesslogic.property.Property p = documentObject.getProperty("memCats");
I was thinking i need to cast it somehow or is it just case of setting the value of p to be a string with the item text in it ie:-
p.Value = "option1"
Any help would be great.
Thanks in advance.
Aron
Hi Aron,
According to the source it is mapping on text values so it should be working like you described. Allthough I see that a comma is always added after the value as you can see in the code snippet below. so maybe you can try p.Value = "option1,"
[code]_text += li.Value + ",";[/code]
If you are useing Action Handlers you must save the document yourself to see the changes (it is a post save).
In Umbraco V4 Events are the way to go to hook into actions. Checkout chapter 6 of this book how to wire it up. I have a few examples on my weblog also. The event you need is Document.BeforeSave
Hope it helps you,
Richard
Thanks for that, setting the value is exactly how it works but I used the item ID and not the text and now it's working perfectly!
Thanks again.
Aron
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.