0

Hi I have some jquery code that checks to see if an asp validator has style="display:inline" If it does I add an error class to the errors parent which is a div.

But when i have two validators this doesnt work. why is that? here is the code

////////// Add Error Class  ////////////////

addErrorClass: function (obj) {


    if ($(obj).parent().find('.errorMessage').parent().css("display") == "inline") {

        $(obj).parent().addClass("error");

    } else {
        $(obj).parent().removeClass("error");
    }


},

////////// Add Error Class /////////////

////////// Validate Form Fields /////////////


ValidateFF: function () {



    $('.required input').blur(function () {


        project.addErrorClass(this);
        if ($(".modal").length) {
            Spacedadi_UI.AdjustRadWindow();
        };

    });


    $('#btnSave').click(function () {

        $('.required input').each(function (index) {

            // Force ASP Validation before click event when using link buttons

            var cErrorID = $(this).parent().find("span").attr('id');
            ValidatorEnable(document.getElementById(cErrorID), true);

            project.addErrorClass(this);

            if ($(".modal").length) {
                project.AdjustRadWindow();
            };
        }); //end of click

        if ($(".modal").length) {
            project.AdjustRadWindow();
        };

    }); // end validate function

},
////////// Validate Form Fields /////////////

HTML Code

                <div class="field required"><asp:Label ID="lbEmail" runat="server" CssClass="label" Text="Email" AssociatedControlID="tbEmail"></asp:Label>
            <asp:TextBox ID="tbEmail" runat="server"></asp:TextBox>

            <asp:RequiredFieldValidator ID="rfvEmail" runat="server" errorMessage="<span class='errorMessage'>Please enter an email address</span>"
                ControlToValidate="tbEmail" CssClass="" ValidationGroup="ValAddContact"
                Display="Dynamic"></asp:RequiredFieldValidator>

            <asp:RegularExpressionValidator ID="revtbEmail" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                ControlToValidate="tbEmail" errorMessage="<span class='errorMessage'>Invalid Email Format</span>" ValidationGroup="ValAddContact"
                CssClass=""></asp:RegularExpressionValidator>
        </div>

Thanks

1 Answer 1

1

I'm not really sure about ASP.NET, but have you tried inspecting the HTML on the page to see if it's renamed anything you're relying on? I seem to remember ASP renaming IDs and Names of elements to ensure they're unique.

You could also try using .hasClass('errorMessage') instead of find(...).

Does the button click event actually fire in the first place?

Sign up to request clarification or add additional context in comments.

1 Comment

Are you wanting the changes made to all occurrences of the errorMessage class when the button is clicked? If so you can use the .each() function: $('.errorMessage').each(function() { ... });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.