How to remove validation options in Edit Mode?

Vote:
 

I'm making a custom Form Element of "Date" type, so I'm extending "TextboxElementBox" like so...

public class DateElementBlock : TextboxElementBlock
{
    public DateElementBlock() : base() { }
}

My custom element will be 

<input type="date" />

but because I'm extending TextboxElementBlock the editor displays a few validation options...

which are not appropriate. I did TRY and create a custom element with a custom validator, but the client side custom error message is not displayed correctly, so I figured as the browser will ensure that the "date" field will have a proper date if it has anything in it at all, so If I could remove all the validation options above except the "Required" validator then my problem would be sorted.

I tried to override the value returned by 

public override string Validators {get;set;}

inside  DateElementBlock.cs, but that only returns a list of ACTIVE validators, so it doesn't control the list of validators presented to the editors.

I think this may require a dojo solution, and I've already inspected the zip files (EPiServer.Forms.zip and EPiServer.Forms.UI.zip) and I'm hoping it works similar to adding a custom element (copy ascx/js file from zip into correct folder location). 

Anyone done anything similar in the past?

#203060
Apr 08, 2019 17:42
Vote:
 

Hi Noel

The Episerver Forms samples code has a date/time element that you might be able to use for inspiration: https://github.com/episerver/EPiServer.Forms.Samples 

David

#203061
Apr 08, 2019 18:06
Vote:
 

Thanks David, browsing that code showed me "AvailableValidatorTypes" (which is the answer I needed)

my element's full *.cs file source:

[ContentType(DisplayName = "Date Picker", GroupName = "Basic Elements", GUID = "...")]
[AvailableValidatorTypes(Include = new Type[] { typeof(RequiredValidator) })]
public class DateElementBlock : TextboxElementBlock
{
    public DateElementBlock() : base() { }

    [ScaffoldColumn(false)]
    public override string PredefinedValue { get { return base.PredefinedValue; } set { base.PredefinedValue = value; } }

    [ScaffoldColumn(false)]
    public override string PlaceHolder { get { return base.PlaceHolder; } set { base.PlaceHolder = value; } }
}
#203088
Edited, Apr 09, 2019 10:34
Vote:
 

Excellent glad it helped Noel :)!

#203103
Apr 09, 2019 12:34
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.