Copied to clipboard

Flag this post as spam?

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


  • Andrey Stepanov 2 posts 72 karma points
    Jan 13, 2016 @ 12:43
    Andrey Stepanov
    0

    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
    • 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?

    Thanks, Andrey

  • Alex Skrypnyk 6175 posts 24176 karma points MVP 8x admin c-trib
    Jan 13, 2016 @ 13:08
    Alex Skrypnyk
    0

    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

  • Andrey Stepanov 2 posts 72 karma points
    Jan 14, 2016 @ 09:26
    Andrey Stepanov
    0

    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

  • Alex Skrypnyk 6175 posts 24176 karma points MVP 8x admin c-trib
    Jan 14, 2016 @ 11:34
    Alex Skrypnyk
    0

    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

  • TheOriginal 22 posts 122 karma points
    Jan 13, 2016 @ 13:17
    TheOriginal
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft