I have a content type with a checkbox/boolean field in the backend edit page that I want to validate. However, I want to validate it against all other db entries of the same content type to ensure that only one of them has this checkbox checked. If one of them already has this boolean true, I want the backend to refuse the submission. The closest forum post I've found to answer this question is this:
But is this what I'm looking for? Currently in the middle of reading this bit of doc but am still uneasy. Thank you.
sender, EventArgs e)
Telerik.Sitefinity.Abstractions.Bootstrapper.Initialized += Bootstrapper_Initialized;
sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
EventHub.Subscribe<IDynamicContentCreatingEvent>(evt => IDynamicContentCreatingEvent(evt));
hey Dmitri, this was super helpful. and i've now got the validation in, however, as someone in the thread i posted above asked; how can I, from inside the Created/Updated events, force the DynamicContent to not be saved upon failure to validate? Thank you
Alright, final question on this topic. I've taken over the LifecycleDecorator and I can validate in it/set the selected option to false based on the validation.
Now, i accept that maybe I can't stop the publishing process from going through. But I would like to atleast alert the user that I've overridden their setting. Is there a way, from the LifecycleDecorator overriding function to alert() the browser or something? Maybe, tie into the sitefinity backend and display a message somewhere at the top of the page? The latter seems like a stretch, but I'm hoping.
I would use this:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Featured reset to false')", true);
but that requires the calling class to be a page.
You should be able to override the ExecuteOnPublish() method and validate. In there you can throw an exception when a setting will be overwritten.
This exception will be shown as a pop-up in the back-end UI.