Copied to clipboard

Flag this post as spam?

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


  • Huw Reddick 1932 posts 6722 karma points MVP 2x c-trib
    Dec 02, 2020 @ 16:52
    Huw Reddick
    0

    Custom validate function

    One final question I think :)

    I am trying to inject a validation into the field for the check, what is the best way to do that?

    I can see that my js checkValidyCommon function is called when the form gets submitted, is there a way to inject a validation item into the validationResults array at this point?

    This was the code I copied for the check validity common

    validationResults = [];
    for (i = 0; i < validators.length; i++) {
        validator = validators[i];
        validationResults.push(checkValidity(validator, value, validityFnName));
    }
    validationResults.push(response);
    
    
    // Add inline validation messages.
    aggregateValidations(validationResults)
        .then(function (result) {
    
            // Add inline validation messages.
            fieldRenderer.validationListElement = addValidationMessages(
                containerElement, result.messages, fieldRenderer.validationListElement);
    
            // Add or remove validation error CSS class.
            if (result.success) {
                containerElement.classList.remove("formulate__field--validation-error");
            } else {
                containerElement.classList.add("formulate__field--validation-error");
            }
    
        });
    
    // Return the validation results.
    return validationResults;
    

    I have a javascript function the returns a success/fail object with a message, is there anyway to get it into the pipeline

  • Nicholas Westby 2054 posts 7104 karma points c-trib
    Dec 02, 2020 @ 17:40
  • Huw Reddick 1932 posts 6722 karma points MVP 2x c-trib
    Dec 02, 2020 @ 17:56
    Huw Reddick
    0

    Thanks, I will have a peruse, hopefully the links will trigger a few braincells into action.

  • Huw Reddick 1932 posts 6722 karma points MVP 2x c-trib
    Dec 02, 2020 @ 21:44
    Huw Reddick
    1

    sorted, thanks for the pointers.

    enter image description here

  • Huw Reddick 1932 posts 6722 karma points MVP 2x c-trib
    Dec 03, 2020 @ 09:14
    Huw Reddick
    0

    Just to let you know I ended up cheating :D

    I could not get it to register my validator, so I added a standard 'requiredtext' validator from the umbraco backoffice, this caused it to fire the checkvalidity functions and I was able to perform my extra validation.

    I just could get this bit to work

    RenderBotcheck.prototype.ensureValidator = function (validations) {
        console.log('ensureValidator');
        if (!validations.length) {
            return [{
                alias: "botcheckRequired",
                configuration: {
                    message: "Please solve the question."
                },
                validationType: "required"
            }];
        } else {
            return validations;
        }
    };
    

    It just never registered the custom validator, so not sure what I have missed, but working ok so happy with it for now.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies