qtip2 not displayed for hidden model elements used for model validation in mvc4

423 views Asked by At

I am using qtip2 for displaying the client side validations in my MVC4 application .following is the code

$(function () {
            // Run this function for all validation error messages
            $('.field-validation-error').each(function () {
                // Get the name of the element the error message is intended for
                // Note: ASP.NET MVC replaces the '[', ']', and '.' characters with an
                // underscore but the data-valmsg-for value will have the original characters
                var inputElem = '#' + $(this).attr('data-valmsg-for').replace('.', '_').replace('[', '_').replace(']', '_');

                var corners = ['top center', 'bottom center'];
                var flipIt = $(inputElem).parents('span.right').length > 0;

                // Hide the default validation error
                $(this).hide();

                // Show the validation error using qTip
                $(inputElem).filter(':not(.valid)').qtip({
                    content: { text: $(this).text() }, // Set the content to be the error message
                    position: {
                        my: corners[flipIt ? 0 : 1],
                        at: corners[flipIt ? 1 : 0],
                        viewport: $(window)
                    },
                    show: {
                        ready: true
                        //modal: {
                        //    on: true
                        //}                                
                    },
                    //hide: false,
                    hide: {
                        event: 'unfocus'//event: 'click mouseleave'
                    },
                    //style: { classes: 'ui-tooltip-red' }
                });
            });
        });

This is working fine until the element on which error message is to be displayed is visible.
I am using the kendo ui MVC helpers for controls like dropdownbox ,selectlist etc.
it hides the original element with its own.following the html generated (check element with id PhysicianType)

    <span class="k-widget k-dropdown k-header input-validation-error" style="margin: 0px 0px 0px 28px; width: 181px; font-family: 'Segoe UI';" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="PhysicianType_listbox" aria-disabled="false" aria-readonly="false" aria-busy="false" aria-activedescendant="PhysicianType_option_selected">
    <span class="k-dropdown-wrap k-state-default" unselectable="on">
    <span class="k-input" unselectable="on">Select Type</span>
    <span class="k-select" unselectable="on">
    </span>
    <input id="PhysicianType" class="input-validation-error" type="text" style="margin: 0px 0px 0px 28px; width: 181px; font-family: 'Segoe UI'; display: none;" name="PhysicianType" data-role="dropdownlist">
    </span>

now i want to display the error message for PhysicianType but at its not visible ;error message is not displayed.I used following code to display tooltip for hidden element

 $(function () {
        $.validator.setDefaults({ ignore: [] });
    });

above code displays the error code for hidden element also but the position of qtip is upper left corner of the screen;not attached to element itself.
Please help to accurately position the qtip2 error in case of hidden element.

1

There are 1 answers

0
A_0 On BEST ANSWER
if (somecondition.value() == 0) { $('span:first', "#NegCdtDDl").qtip({ content: { text: "Please Select value for control" }, show: { ready: true }, position: { at: 'top center', my: 'bottom center', viewport: $(window) }, hide: false }); } else { $('span:first', "#NegCdtDDl").qtip('destroy'); }