|
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using Microsoft.AspNetCore.Http; |
|
using Umbraco.Cms.Core.Composing; |
|
using Umbraco.Cms.Core.DependencyInjection; |
|
using Umbraco.Forms.Core; |
|
using Umbraco.Forms.Core.Enums; |
|
using Umbraco.Forms.Core.Models; |
|
using Umbraco.Forms.Core.Providers; |
|
using Umbraco.Forms.Core.Services; |
|
|
|
namespace NSVSAC.Umbraco.WebApplication.App_Plugins.HumbleForms |
|
{ |
|
public class ConfirmationFieldType : FieldType |
|
{ |
|
public ConfirmationFieldType() |
|
{ |
|
this.Id = new Guid("08b8057f-06c9-4ca5-8a42-fd1fc2a06eff"); // Replace this! |
|
this.Name = "Confirmation"; |
|
this.Description = "Confirm previous entries before proceeding."; |
|
this.Icon = "icon-autofill"; |
|
this.DataType = FieldDataType.Bit; |
|
this.SortOrder = 10; |
|
this.SupportsRegex = true; |
|
} |
|
|
|
public override string GetDesignView() => "~/App_Plugins/HumbleForms/confirmationField.html"; |
|
public override string RenderView => "~/App_Plugins/HumbleForms/confirmationField.html"; |
|
|
|
|
|
// 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, HttpContext context, IPlaceholderParsingService placeholderParsingService) |
|
{ |
|
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, placeholderParsingService)); |
|
|
|
return returnStrings; |
|
} |
|
} |
|
|
|
public class Startup : IComposer |
|
{ |
|
public void Compose(IUmbracoBuilder builder) |
|
{ |
|
builder.WithCollectionBuilder<FieldCollectionBuilder>() |
|
.Add<ConfirmationFieldType>(); |
|
} |
|
} |
|
} |