Copied to clipboard

Flag this post as spam?

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


  • Chris 5 posts 75 karma points
    Apr 28, 2017 @ 15:36
    Chris
    0

    Product Saving Event - Not showing messages on cancel

    Hey,

    I am trying to build some custom validation for products. I need to validate fields on an Extended Content Type.

    As a test I wanted to see if I can cancel the Saving event. I tried the following:

        public class ProductValidationEventHandler : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication,
            ApplicationContext applicationContext)
        {
            ProductService.Saving += ValidateProduct; // rasied before the content has been saved.
            base.ApplicationStarted(umbracoApplication, applicationContext);
        }
    
        private void ValidateProduct(IProductService sender, SaveEventArgs<IProduct> e)
        {
            e.CancelOperation(new EventMessage("Validation", "TEST - THIS SHOULD NOT SAVE", EventMessageType.Error));
        }
    }
    

    While the code is called, and the save appears to be cancelled, the message is not being displayed.

    Am I using the right event? Is there another approach to custom validation in Merchello?

  • Alex Skrypnyk 3643 posts 12427 karma points mvp
    May 07, 2017 @ 21:08
    Alex Skrypnyk
    0

    Hi Chris

    Do you want to see validation message in the Umbraco back office?

    Thanks,

    Alex

  • Alex Skrypnyk 3643 posts 12427 karma points mvp
    May 12, 2017 @ 10:56
    Alex Skrypnyk
    0

    Hi Chris

    Did you solve your issue? Can I help you?

    Alex

  • Chris 5 posts 75 karma points
    May 19, 2017 @ 15:03
    Chris
    0

    Hey

    Sorry for the late reply, I was away from the office.

    I haven't solved it - I got sidetracked by other work. To answer your question, yes I'm trying to get the event message to show up in the back office.

    The back story is we have a merchello integration with several kinds of product (each with their own DocType). In one of the products I have a product picker to select related items. However I want to limit that picker to only allow a subset of the available product types.

    My plan was to implement a validation handler to check that and show an error / disable the save. Not sure if this is the correct or best approach :)

    Cheers, Chris

Please Sign in or register to post replies

Write your reply to:

Draft