Copied to clipboard

Flag this post as spam?

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


  • Kieron 152 posts 390 karma points
    Aug 29, 2018 @ 12:02
    Kieron
    0

    Handling Start Date & End Date, with a 'To Be Confirmed' Flag?

    Hi guys, I have the below document type:

    enter image description here

    Now as you can see, when someone adds something they can select whether the event doesn't have a date yet, which is fine, but if they want to add an event and the event has a date, I want that to be mandatory, so you cant add events that are neither TBC, or without a date. But that then means if the date is TBC, then you'd still have to pick a date.

    How this was handled in the past was that the description would advise a rough date is required and the client could choose the rough date, then choose TBC, then that would be shown instead of the rough date.

    But is there anything anyone can think of to do it any differently?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Aug 29, 2018 @ 12:32
    Dave Woestenborghs
    1

    Hi Kieron,

    I don't think can do that out of the box.

    An option would be to create a custom property editor that combines the 3 fields. But I guess this an existing site. So that would bring other issues eg. you need to migrate the data from the existing 3 fields in to one.

    Dave

  • Kieron 152 posts 390 karma points
    Aug 29, 2018 @ 12:33
    Kieron
    0

    It's a new site actually, so I could definitely do that, though I suspect it's not easy? D:

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Aug 29, 2018 @ 12:45
    Dave Woestenborghs
    1

    You probably can reuse the views or datatypes you already created for the seperate fields.

    I wrote about this once : https://24days.in/umbraco-cms/2014/umbraco-angular-tips/

    The article is now 4 years old. So it could be that some of the code is not really up to date anymore.

    You can also have a look at the source code of my Tour Editor package to see how I reuse some built in editors (eg. slider, rte)

    https://github.com/dawoe/umbraco-tour-editor/blob/develop/Source/Our.Umbraco.TourEditor/Web/App_Plugins/TourEditor/backoffice/toureditor/subviews/stepdetails.html

    https://github.com/dawoe/umbraco-tour-editor/blob/develop/Source/Our.Umbraco.TourEditor/Web/App_Plugins/TourEditor/scripts/controllers/step-details-controller.js#L49

    For the checkbox you could use the umb-toggle directive

    Dave

  • Kieron 152 posts 390 karma points
    Aug 29, 2018 @ 12:52
    Kieron
    0

    Thanks for your response, upon looking through the resources it would appear im out of my depth so, for now, I will not be able to resolve this haha.

    Thank you.

  • Matthew Wise 271 posts 1373 karma points MVP 4x c-trib
    Aug 29, 2018 @ 13:00
    Matthew Wise
    1

    Not really a solution but you could add a message to help the CMS user get this correct, uEditorNotes is really good for that

    https://our.umbraco.com/projects/backoffice-extensions/ueditornotes/

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Aug 29, 2018 @ 13:06
    Dave Woestenborghs
    0

    Hi Matthew

    Not a solution indeed, but a nice work around. I use uEditorNotes a lot. Even that much they were part of 2 of my codegarden talks.

    Once in make your editors happy (I think 2015) and one this year in my lightning talk about tours.

    Dave

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Aug 29, 2018 @ 13:55
    Dave Woestenborghs
    1

    Hi Matthew,

    Not a solution indeed. But a nice work around. I think I use uEditorNotes in 90% of my projects.

    I like them so much that I mentioned it in 2 Codegarden talks.

    • Make your editors happy (2015... I think... the last one in Copenhagen)
    • A tour of the tours (2018)

    Dave

  • Rami H 13 posts 141 karma points
    Aug 29, 2018 @ 15:46
    Rami H
    0

    Hi Kieron,

    Update: added using statements as per below

    If you don't want to go the custom property editor way, another option could be to run a check when a node is saved/published and to make sure it has appropriate properties filled out, and stop it from publishing if the fields aren't valid. Create a class that inherits from ApplicationEventHandler and append some checks.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Http;
    using Umbraco.Core;
    using Umbraco.Core.Events;
    using Umbraco.Core.Logging;
    using Umbraco.Core.Models;
    using Umbraco.Core.Publishing;
    using Umbraco.Core.Services;
    using Umbraco.Web;
    
    public class RegisterEvents : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            //append our method to the Saving event
            ContentService.Saving += ContentService_Saving;
        }
        //Our custom checks
        private void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e)
        {
            foreach(var content in e.SavedEntities)
            {
                //run your checks and throw the error if no value where needed.
                //if the value for create date is null, etc.
                if(content.GetValue("eventCreateDate") == null)
                {
                    //cancel the event of saving and trigger a warning message
                    e.Cancel = true;
                    e.Messages.Add(new EventMessage("Warning", "Event needs either TBC enabled or an event start date.", EventMessageType.Error));
                 }
                //add as many checks as needed
            }
        }
    }
    

    You can create a file in App_Code, call it RegisterEvents.cs or something like that and stick that guy in there.

    Let us know how it goes!

  • Kieron 152 posts 390 karma points
    Aug 29, 2018 @ 16:14
    Kieron
    0

    I'd like to try this method, but I don't have an App_Code folder, which is a good start lol.

  • Rami H 13 posts 141 karma points
    Aug 29, 2018 @ 16:28
    Rami H
    0

    Haha! Then that's easy to remedy, create one in your website's root folder ;)

    Here's all the events reference

  • Kieron 152 posts 390 karma points
    Aug 30, 2018 @ 08:13
    Kieron
    0

    Hey, thanks that bit was easier than i thought :D

    Ive added it in and currently facing this one:

    https://gyazo.com/ca3b39f8f8dc91d0e0c8f09dbc7bd6d5

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
    
    Compiler Error Message: CS0246: The type or namespace name 'ApplicationEventHandler' could not be found (are you missing a using directive or an assembly reference?)
    
    Source Error:
    
    
    Line 1:  public class RegisterEvents : ApplicationEventHandler
    Line 2:  {
    Line 3:      protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    

    Thanks for your help so far!

  • Rami H 13 posts 141 karma points
    Sep 03, 2018 @ 15:30
    Rami H
    0

    Hi Kieron,

    You'll need to add the appropriate using statements at the top of your file. I updated my previous example to reflect the using statements you may want to use. ApplicationEventHandler is part of Umbraco.Core. Here is an example of my using statements for one of my files for Umbraco Events.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Http;
    using Umbraco.Core;
    using Umbraco.Core.Events;
    using Umbraco.Core.Logging;
    using Umbraco.Core.Models;
    using Umbraco.Core.Publishing;
    using Umbraco.Core.Services;
    using Umbraco.Web;
    
    public class RegisterEvents : ApplicationEventHandler
    {
        ...
    }
    

    If you're using Visual Studio, Intellisense will give you hints at using statements when you hover over squiggly lines and click on the light bulb or click on "Show Potential Fixes". I updated my first example to reflect the using statements.

    Add those using statements to the top of your RegisterEvents.cs file and let us know how it goes!

Please Sign in or register to post replies

Write your reply to:

Draft