I would like to apply different validation rules for fields depending on the value of one field. They should applied for publishing (as normal validation).
Example
We have Slide document type, with following fields:
Layout
Header
Text
Image
Layout field is drop down field that can take following values: Text or Text with Image
When Layout is Text, following fields are required: Header, Text (300 character max)
When Layout is Text with Image, following fields are required: Header, Text (100 character max), Image
Is there a way to implement this functionality, somehow?
I've personally done this by using javascript, simply detect when the error message is shown, use the class that is attatched to it decide when to add an error class to the input field enabling custom validation weather you want a differant color border on the input or to add error placeholder or what ever, an example of what i mean is:
if($(".errorClass").length > 0)
{
$(this).prev().addClass("customErrorClass");
// What the above line does is add a class to the input field
// previouse to the current error message
}
Also if you don't want the default error message to show still simply hide it in css
Document type - Cross field custom validation
I would like to apply different validation rules for fields depending on the value of one field. They should applied for publishing (as normal validation).
Example
We have Slide document type, with following fields:
Layout field is drop down field that can take following values: Text or Text with Image
When Layout is Text, following fields are required: Header, Text (300 character max)
When Layout is Text with Image, following fields are required: Header, Text (100 character max), Image
Is there a way to implement this functionality, somehow?
Thanks, Andrey
Hi Andrey,
As I see you can create custom property editor something like - "Textbox with custom validation", and handle your validation rules via angular.
Tutorials how to create property editor: https://our.umbraco.org/documentation/Tutorials/Creating-a-Property-Editor/
http://creativewebspecialist.co.uk/2013/08/23/how-i-built-my-first-property-editor-for-umbraco-belle/
Thanks, Oleksandr
Hi Alex,
Thanks for you reply, I was considering this but how can I get the values of multiple fields and validate them within Property editor JS code?
Cheers, Andrey
Hi Andrey,
One way is to put all fields to one property editor. Another is to get values of another field via DOM.
Thanks,
Alex
I've personally done this by using javascript, simply detect when the error message is shown, use the class that is attatched to it decide when to add an error class to the input field enabling custom validation weather you want a differant color border on the input or to add error placeholder or what ever, an example of what i mean is:
Also if you don't want the default error message to show still simply hide it in css
is working on a reply...