Dynamic prevalues in the new DataEditorSettings in 4.6.1?
I'm using 4.6.1, and have a query about the new [DataEditorSetting(...)] properties when using a usercontrolwrapper.
I need to have two properties. The first - "Statuses" is a "Values" type, to allow a user to enter a list of possible status values. The second property - "DefaultStatus" - is a RadioButtonList from which the user should to be able to select one of the values from the first property.
Basically, I need to be able to populate the prevalues of my "RadioButtonList" property with the contents of my "Values" property:
The "Values" type is stored as a semi-colon separated list, and the RadioButtonList's prevalues property requires a comma-separated list, but I'm not sure how (or at what point, or whether it's even possible) to dynamically create the prevalues of the RadioButtonList from the values entered in the "Statuses" list.
Thanks for looking at this - really appreciate it.
I've been experimenting based on your article, and am trying to create a data editor setting type which also uses a DropDownList control, but I want to populate the items of that control with the prevalues of a second type.
Initially, I had thought of passing the name of the "Values" type to my new type in the prevalues parameter, like this:
[DataEditorSetting("Statuses", type=typeof(umbraco.editorControls.SettingControls.Values), description="Enter list of possible statuses")] publicstring TestValues { get; set; }
One follow-up question - instead of hard-coding the dataTypeNodeID in GetSettings, is is possible to work out the ID of the containing (parent?) data type from within the new DataEditorSettingType's RenderControl method?
It's so simple when you know how! Thanks for all your help - here's the final class.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI.WebControls; using umbraco.cms.businesslogic.datatype; using umbraco.editorControls.SettingControls;
// get ID of this data type from querystring int dataTypeId; if (Int32.TryParse(HttpContext.Current.Request["id"], out dataTypeId)) {
// get all data editor settings for this data type DataEditorSettingsStorage des = newDataEditorSettingsStorage(); var settings = des.GetSettings(dataTypeId);
// find the setting where the key matches the prevalue passed in Setting<string, string> thisSetting = settings.Find(s => s.Key == this.Prevalues[0]); if (thisSetting.Key != null) { // split the semi-colon separated values into a string array string[] listValues = thisSetting.Value.Trim(';').Split(';'); foreach (string thisVal in listValues) { // add the items into the dropdown list ddl.Items.Add(newListItem(thisVal));
// set the dropdown list's selected value (if applicable) if (thisVal == _val) { ddl.SelectedValue = thisVal; } } } } return ddl; } } }
Dynamic prevalues in the new DataEditorSettings in 4.6.1?
I'm using 4.6.1, and have a query about the new [DataEditorSetting(...)] properties when using a usercontrolwrapper.
I need to have two properties. The first - "Statuses" is a "Values" type, to allow a user to enter a list of possible status values. The second property - "DefaultStatus" - is a RadioButtonList from which the user should to be able to select one of the values from the first property.
Basically, I need to be able to populate the prevalues of my "RadioButtonList" property with the contents of my "Values" property:
The "Values" type is stored as a semi-colon separated list, and the RadioButtonList's prevalues property requires a comma-separated list, but I'm not sure how (or at what point, or whether it's even possible) to dynamically create the prevalues of the RadioButtonList from the values entered in the "Statuses" list.
Any ideas?
Cheers,
Mike
Comment author was deleted
@Mike, not possible with the default data editor settings types, but you could do it with a custom one
Will see if I can find some time to put an example together
For now here is some details on creating a custom data editor setting type:
http://www.nibble.be/?p=96
Hi Tim
Thanks for looking at this - really appreciate it.
I've been experimenting based on your article, and am trying to create a data editor setting type which also uses a DropDownList control, but I want to populate the items of that control with the prevalues of a second type.
Initially, I had thought of passing the name of the "Values" type to my new type in the prevalues parameter, like this:
But then, I'm not sure how to access the prevalues of the Values type... this is kind of what I was thinking:
Am I completely off track?
Thanks,
Mike
Comment author was deleted
Yup would also do it like that, then you'll simply need to fetch the stored values based on the name
That's good to know :-)
The bit I'm missing is how to fetch the stored values... is there a method I can call which will return them?
Cheers,
Mike
Comment author was deleted
Yup you should be able to use
umbraco.cms.businesslogic.datatype.DataEditorSettingsStorage
use the GetSettings(int dataTypeNodeID) method to fetch all setting values and then simply select the one with the correct alias
Thanks Tim, it's now working :-)
One follow-up question - instead of hard-coding the dataTypeNodeID in GetSettings, is is possible to work out the ID of the containing (parent?) data type from within the new DataEditorSettingType's RenderControl method?
Thanks again,
Mike
Comment author was deleted
Sure, guess easiest way is to simply fetch it from the request collection (id param)
httpcontext.current.request['id']
It's so simple when you know how! Thanks for all your help - here's the final class.
Comment author was deleted
Awesome, glad I could help!
So what's your thoughts on the whole data editor settings improvement?
is working on a reply...