Hi everybody,
I need to set two different data consent fields that needs two show up based on conditional logic on the value of a dropdown.
So if dropdown is value1 show dataConsent1, otherwise show dataConsent2.
So far so good.
The problem is that Umbraco Forms wants them to be both checked, also if one is not showing. This appears to happen only with Data Consent field, I've tried with other mandatory fields and there is not any problem.
I've overriden the default DataConsent cshtml but I don't see any major difference.
public class DataConsentFixed : Umbraco.Forms.Core.Providers.FieldTypes.DataConsent
{
private static readonly string s_trueString = true.ToString().ToLowerInvariant();
public override IEnumerable<string> ValidateField(Form form, Field field, IEnumerable<object> postedValues, HttpContextBase context, IFormStorage formStorage)
{
Dictionary<Guid, string> fieldValues = form.AllFields.ToDictionary((Field f) => f.Id, (Field f) => string.Join(", ", f.Values ?? new List<object>()));
List<string> list = new List<string>();
if (field.Mandatory && !postedValues.Any((object x) => string.Equals(x.ToString(), s_trueString, StringComparison.InvariantCultureIgnoreCase)))
{
bool flag = true;
if (field.HasCondition())
{
flag = !field.Condition.IsCircular(form) && field.Condition.IsVisible(form, fieldValues);
}
if(flag)
{
string item = ((!string.IsNullOrWhiteSpace(field.RequiredErrorMessage)) ? field.RequiredErrorMessage : "Consent is required to store and process the data in this form.");
list.Add(item);
}
}
return list;
}
}
In the Validate Field method of the DataConsent field type the visibility of the field was not taken into account. Overriding the method with some code taken from the FieldType.cs did the trick.
Alternative DataConsent
Hi everybody, I need to set two different data consent fields that needs two show up based on conditional logic on the value of a dropdown.
So if dropdown is value1 show dataConsent1, otherwise show dataConsent2. So far so good.
The problem is that Umbraco Forms wants them to be both checked, also if one is not showing. This appears to happen only with Data Consent field, I've tried with other mandatory fields and there is not any problem.
I've overriden the default DataConsent cshtml but I don't see any major difference.
Any clue? thanks
Solved:
In the Validate Field method of the DataConsent field type the visibility of the field was not taken into account. Overriding the method with some code taken from the FieldType.cs did the trick.
is working on a reply...