I was developing a custom field type that inherits from SPFieldUrl. I overrided the GetValidatedString(object value) method to perform the validation when the field was set to be mandatory. My overriden method however was not called by SharePoint, and hence the required field validation failed.
It turns out that it was because I was returning null in my field control class when a value was not specified for the field:
public override object Value { get { EnsureChildControls(); if (String.IsNullOrEmpty(txtUrl.Value)) { return null; } //... } //... }
It appears that SharePoint does not call GetValidatedString() when the value is null. I changed the above code to below and everything works as expected:
if (String.IsNullOrEmpty(txtUrl.Value)) { return new SPFieldUrlValue(); }
In my next post I will provide a walkthrough of developing a custom field type that allows users to intuitively browse, upload and display an image to a SharePoint list. Watch this space :).