Copied to clipboard

Flag this post as spam?

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


  • Thomas Mulder 15 posts 86 karma points
    Sep 07, 2015 @ 13:04
    Thomas Mulder
    0

    e.Cancel = true returning to content node 0; resulting in 404 not found

    Hi,

    I'm doing some validation in saving event. When some dates are in conflict, the saving event is cancelled by setting

    e.Cancel = true;
    

    in the saving event.

    The problem is, after this cancellation, the page is being returned to /umbraco/backoffice/UmbracoApi/Content/GetById?id=0

    Which evidently results in a : 404 (Not Found), and the user having to fill in all fields again, which is not a desirable effect..

    How do I return back to the page where all the fields are still filled in?

    EDIT: this question on stackoverflow concerns the same problem, but no answers have been provided yet. One of the comments suggests: "assign the parentId of the cancelled entity while creating to avoid redirection to 0 node." but I don't quite see how to do that to avoid the redirect to 0 node (which is what I would like to do)

  • Marc Goodson 2144 posts 14347 karma points MVP 8x c-trib
    Sep 07, 2015 @ 19:01
    Marc Goodson
    100

    Hi Thomas

    As you've probably guessed, the Save action of Umbraco is what creates the item in the Umbraco database, and therefore gives the item an Id.

    The built-in RegEx validation on Umbraco fields allows the User to Save the content (even with invalid elements) but prevents the elements from being published if the validation rules do not match.

    To be consistent with this approach, would it be appropriate, with the validation you are trying to do, to move your custom validation to the ContentService.Publishing event ? and just cancel the publishing of the incorrect data instead ?

    regards

    Marc

  • Thomas Mulder 15 posts 86 karma points
    Sep 08, 2015 @ 07:07
    Thomas Mulder
    0

    Hi Marc,

    Thanks for your reply, but itis however not really an option at this point, to start to move everything now. For example Events are already saved on exchange server, and items are placed in datefolders based on the dates entered by the user. If these dates are incorrect, it's being saved in the wrong place... Besides this flaw on the cancel event, the app is near completion, so this kind of refactoring wasn't quite the answer I was hoping for..

    Right now I'd just like to return back to the editing page, so the user can correct their mistakes and try again. When I create an item, it goes to the Id of the parent, and creates a new item under that Id like so: edit/1190?doctype=Event&create=true So how would I go about to return back to the same page and correct the mistakes?

    Thanks.

    EDIT: If there's no other option I guess I'll have to do the refactoring you said, your answer is probably correct, but it's not quite what I had hoped.. Am I making sense here? :-)

  • Marc Goodson 2144 posts 14347 karma points MVP 8x c-trib
    Sep 08, 2015 @ 18:32
    Marc Goodson
    0

    Hi Thomas

    I may be misunderstanding, but is it an option for you, (to avoid refactoring at this stage)

    to not cancel the save event - but to instead move any item that doesn't pass your validation to a different folder ?

    eg instead of the correct date folder (if it passes validation) to some kind of 'requires review' folder node.

    The item would be saved, and so could be re-edited; and you could prevent the item from being published from the 'requires review' folder.

    Re-saving the item from underneath the 'requires review' would fire your save event logic again, and it could be moved to the correct folder.

    or is that nuts?

  • Thomas Mulder 15 posts 86 karma points
    Sep 11, 2015 @ 15:03
    Thomas Mulder
    0

    Hi Marc,

    The more I thought about it, the better your first answer became.. It was a bit of a hassle, but I ended up refactoring the way you said and it worked as hoped. Thanks for your reply!

Please Sign in or register to post replies

Write your reply to:

Draft