Copied to clipboard

Flag this post as spam?

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


  • Ayo Adesina 445 posts 1059 karma points
    Sep 12, 2017 @ 08:40
    Ayo Adesina
    0

    How to reuse Umbraco's Validation in Custom Section

    I have a custom section and I'm trying to get validation working exactly the same way it works in Umbraco's content section.

    If i Include the show-validation css class in my like this:

       <form name="campaignForm" val-form-manager class="show-validation">
    

    The validation errors are displayed before the user actually clicks the save button. In my save method I have this if statment that stops the form being submitted,

              function save() {
            if ($scope.campaignForm.$invalid) {
    
                console.log("Validation working now how to apply the ccss class?")
                return false;
    
            }
         //Save logic here
    

    how do I apply the CSS class only when the form is being posted?

  • Ayo Adesina 445 posts 1059 karma points
    Sep 12, 2017 @ 14:27
    Ayo Adesina
    0

    I tried removing the class and doing this....

        function save() {
            if ($scope.campaignForm.$invalid) {
                console.log("Validation Error")
    
                $scope.campaignForm.$addClass('show-validation');
                $compile(campaignForm)(scope);
    
    
                return false;
            }
    

    Still no joy........

  • Ayo Adesina 445 posts 1059 karma points
    Sep 12, 2017 @ 15:16
    Ayo Adesina
    0
        function save() {
            if ($scope.campaignForm.$invalid) {
                console.log("Validation Error")
    
                angular.element("[name='campaignForm']").addClass('show-validation')
    
                return false;
            }
    

    This works, but is this really how it should be done? becuase then I have to write code to remove it...

    hmm works but dosn't feel right

Please Sign in or register to post replies

Write your reply to:

Draft