Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Douglas Ramalho 1 post 21 karma points
    Jul 01, 2015 @ 13:08
    Douglas Ramalho
    0

    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 .

    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;
                        }
                    }
                }
            }
        }
    
  • Flavio Henrique Moura Stakoviak 1 post 21 karma points
    Jul 01, 2015 @ 14:37
    Flavio Henrique Moura Stakoviak
    0

    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.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies