I've created a custom field type for contour which is basically just a drop down list, (of countries available for trading / shipping as defined in Tea Commerce)
I want to be able to set a default value based on a custom member property; i.e. I would like to supply {member.country} to the DefaultValue field and have contour add the 'selected' attribute to the correct <option> e.g. if {member.country} = 2 then 'Another Country' should be selected.
So how do I implement DefaultValue on a custom field type? Do I have to do it all myself (check if curly brackets in string, get hold of current member, look up correct property etc etc) or just overide something somewhere?
Well you need to add a default value setting and then add some code to set the value of the control to the default value, you don't need to worry about the member stuff, just using the shortcuts should give you the right value.
So you'll need to add
[Attributes.Setting("DefaultValue", description = "Enter a default value", control = "Umbraco.Forms.Core.FieldSetting.TextField")] public string DefaultValue { get; set; }
And this is a snippet from the default dropdownlist where it checks the default value and adds the list items
string dv = string.Empty;
if (DefaultValue != null && DefaultValue != string.Empty)
dv = StringHelper.ParsePlaceHolders(HttpContext.Current, DefaultValue);
foreach (var prevalue in this.AssociatedField.PreValueSource.Type.GetPreValues(this.AssociatedField))
{
ListItem li = new ListItem(Umbraco.Forms.Data.DictionaryHelper.GetText(prevalue.Value), prevalue.Id.ToString());
Default Value for custom field type
Hi All,
I've created a custom field type for contour which is basically just a drop down list, (of countries available for trading / shipping as defined in Tea Commerce)
It renders;
<select>
<option value="">Please Choose...</option>
<option value="1">A Country</option>
<option value="2">Another Country</option>
</select>
I want to be able to set a default value based on a custom member property; i.e. I would like to supply {member.country} to the DefaultValue field and have contour add the 'selected' attribute to the correct <option> e.g. if {member.country} = 2 then 'Another Country' should be selected.
So how do I implement DefaultValue on a custom field type? Do I have to do it all myself (check if curly brackets in string, get hold of current member, look up correct property etc etc) or just overide something somewhere?
Many Thanks,
Tom
Comment author was deleted
Well you need to add a default value setting and then add some code to set the value of the control to the default value, you don't need to worry about the member stuff, just using the shortcuts should give you the right value.
So you'll need to add
And this is a snippet from the default dropdownlist where it checks the default value and adds the list items
Hi Tim,
Brilliant, Thanks,
StringHelper.ParsePlaceHolders(HttpContext.Current, DefaultValue);
Was what I was after :)
Many Thanks,
Tom
is working on a reply...