I created a Data Type , using the Image Cropper as my Property editor, after that, I use the Data Type as property in one of my document types, and I checked the " Mandatory " .
When I try save the node without insert an image in my property , Umbraco always save the node , but not publish him , and after saving the system returns an error message Informing that " Property has errors " how we expected .
The big problem is that this is wrong , because the property is Mandatory , and Umbraco should validate this Image Crooper to save.
I tried use the Content Service to cancel the event save when the property is null, but after cancel in ContentService_Saving method the user is redirect to an url like "umbraco/#/content /content/edit/0 " , and the entire page is blank.
How can I cancel the save of a node with a data type Cropper Image That Is mandatory ? but I need to do this without redirect the user to a blank page .
void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e)
{
foreach (var item in e.SavedEntities.Where(o => o.ContentType.Alias.Equals("DinamoCliente")))
{
if (!item.IsNewEntity())
{
if (item.HasProperty("logo"))
{
if (item.GetValue("logo") != null)
{
dynamic a = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(item.GetValue("logo").ToString());
e.Cancel = !(a != null && !string.IsNullOrEmpty(a.src));
}
else
{
e.Cancel = true;
}
}
}
}
}
Problems of validation with mandatory property
Hello everyone .
I created a Data Type , using the Image Cropper as my Property editor, after that, I use the Data Type as property in one of my document types, and I checked the " Mandatory " .
When I try save the node without insert an image in my property , Umbraco always save the node , but not publish him , and after saving the system returns an error message Informing that " Property has errors " how we expected .
The big problem is that this is wrong , because the property is Mandatory , and Umbraco should validate this Image Crooper to save.
I tried use the Content Service to cancel the event save when the property is null, but after cancel in ContentService_Saving method the user is redirect to an url like "umbraco/#/content /content/edit/0 " , and the entire page is blank.
How can I cancel the save of a node with a data type Cropper Image That Is mandatory ? but I need to do this without redirect the user to a blank page .
Hi Douglas,
I think it's not possible to do what you intend to.
I recommend you reading Umbraco Documentation in order to understand post validation workflow.
is working on a reply...