For some reason it is not saving when I submit. I can debug the variable and see that the value is being set, but when I navigate away or refresh then the value is gone.
I tried to use your settings and it still doesn't save. Here is my code:
public class NewTestField : FieldType
{
[Setting("Test Setting", view = "TextField")]
public string TestSetting { get; set; }
public NewTestField()
{
this.Id = new Guid(FieldTypeId.GetNewTestFieldId());
this.Name = "AgreementsField";
this.Description = "Render a custom text field.";
this.Icon = "icon-autofill";
this.DataType = FieldDataType.String;
this.SortOrder = 10;
this.SupportsRegex = true;
}
public override string GetDesignView()
{
return "/App_Plugins/UmbracoForms/Backoffice/Common/FieldTypes/hiddenfield.html";
}
public override bool HideLabel
{
get { return true; }
}
public override bool StoresData
{
get { return true; }
}
// You can do custom validation in here which will occur when the form is submitted.
// Any strings returned will cause the submit to be invalid!
// Where as returning an empty ienumerable of strings will say that it's okay.
public override IEnumerable<string> ValidateField(Form form, Field field, IEnumerable<object> postedValues, HttpContextBase context)
{
var returnStrings = new List<string>();
if (!postedValues.Any(value => value.ToString().ToLower().Contains("custom")))
{
returnStrings.Add("You need to include 'custom' in the field!");
}
// Also validate it against the original default method.
returnStrings.AddRange(base.ValidateField(form, field, postedValues, context));
return returnStrings;
}
}
Umbraco Forms custom field type custom settings property not saving
I have created a new custom field type and within that a settings property.
For some reason it is not saving when I submit. I can debug the variable and see that the value is being set, but when I navigate away or refresh then the value is gone.
Any ideas? :)
This is how we're doing our custom field types, can you show the rest of the FieldType code?
@ianhoughton Did you ever get the validation-attribute to work? When I've added it no validation is performed.
Refering to this:
I tried to use your settings and it still doesn't save. Here is my code:
What version of forms does this work on for you?
is working on a reply...