-
Is there an option to setting Fields to 'Required'? i.e. 'Title' text field should not be empty when saving. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @wws-inc, You could use the "Hooks" in Piranha which will allow you to validate your page before it's saved. In your Startup.cs, you can register the Hook like so: App.Hooks.Pages.RegisterOnBeforeSave(model => I've found the Hooks very useful when validating content and you can also see in the example code, you could check for field length and even use regex to validate the content. Using this method you can validate properties on the page. I also have an extension method that allows you to validate properties in regions too if you would like it. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Hello @r4g-jon, Thanks! I'll try that.. |
Beta Was this translation helpful? Give feedback.
Hi @wws-inc,
You could use the "Hooks" in Piranha which will allow you to validate your page before it's saved.
In your Startup.cs, you can register the Hook like so:
App.Hooks.Pages.RegisterOnBeforeSave(model =>
{
if (string.IsNullOrWhitespace(model.Title)
hrow new ValidationException("The Title field must be set");
}
I've found the Hooks very useful when validating content and you can also see in the example code, you could check for field length and even use regex to validate the content. Using this method you can validate properties on the page. I also have an extension method that allows you to validate properties in regions too if you would like it.
Hope this helps!