Copied to clipboard

Flag this post as spam?

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


  • Chris 10 posts 100 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 6132 posts 23951 karma points MVP 7x admin c-trib
    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 6132 posts 23951 karma points MVP 7x admin c-trib
    May 12, 2017 @ 10:56
    Alex Skrypnyk
    0

    Hi Chris

    Did you solve your issue? Can I help you?

    Alex

  • Chris 10 posts 100 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

  • Louis Ferreira 69 posts 265 karma points
    Dec 20, 2017 @ 11:07
    Louis Ferreira
    0

    Hey Chris

    Did you get a solution for the messages yet?

    I too am looking for a way to show error messages on my question.

    Cheers

    Louis

  • Ronen Rimon 22 posts 124 karma points
    Jan 16, 2019 @ 11:36
    Ronen Rimon
    0

    Hi Louis, did you have a solution for this? If so, please share it.

    thanks

    Ronen

Please Sign in or register to post replies

Write your reply to:

Draft