1

I am using MVC View with HTML helper form with jQuery Steps. And, working on the validation . But tooltipster always fail with initialization. Have already gone through all the post. But somehow not working. My code snippets as below

Script:

<script src="~/Scripts/tooltipster/jquery.tooltipster.js"></script>
<script src="~/Scripts/tooltipster/jquery.tooltipster.min.js"></script>
<link href="~/Scripts/tooltipster/tooltipster.css" rel="stylesheet" />
<script>

    function resizeJquerySteps() {
        if ($('.body.current').outerHeight() > $('.wizard .steps').outerHeight()) {
            $('.wizard .content').animate({ height: $('.body.current').outerHeight() }, "slow");
        } else {
            $('.wizard .content').animate({ height: $('.wizard .steps').outerHeight() }, "slow");
        }
    }
    $(document).ready(function () {

        var form = $("#RequestStepsForm");

        form.tooltipster({
            trigger: 'custom',
            onlyOne: false,
            position: 'right'
        }); 

        //form.validate({
        //    errorPlacement: function errorPlacement(error, element) { element.before(error); },
        //    rules: {
        //        confirm: {
        //            equalTo: "#password"
        //        }
        //    }
        //});

        //jQuery.validator.setDefaults({
        //    debug: true,
        //    success: "valid"
        //});
        //form.validate({
        //    rules: {
        //        'User.FirstName': {
        //            required: true
        //        }

        //    }

        //});

        jQuery(function ($) {
           form.validate({

               //errorElement: 'div',
               //errorPlacement: function(error, element) {
               //    $(element).tooltip({
               //        content: 'the error message goes here'
               //    });
               //},

              // errorPlacement: function(error, placement) {
              //     var text = error.text();
              //      placement.tooltip({
              //             content: function(){ return text; }
              //         }).tooltip('open');
              //},

                   errorPlacement: function (error, element) {
                       $(element).tooltipster('update', $(error).text());
                       $(element).tooltipster('show');
                   },
                   success: function (label, element) {
                       $(element).tooltipster('hide');
                   },

               rules: {
                    'User.FirstName': {
                        required: true
                    },
                    'User.LastName': {
                            required: true
                    }
               }

               //messages: {

               //    'User.FirstName': {
               //        required: "You must enter the First Name"
               //    },
               //    'User.LastName': {
               //        required: "You must enter the Last Name"
               //    }

               //}
           });
        });

        form.children("div").steps({
            headerTag: "h1",
            bodyTag: "fieldset",
            transitionEffect: "slideLeft",
            stepsOrientation: "vertical",
            onStepChanging: function (event, currentIndex, newIndex) {

                alert(currentIndex);
                form.validate().settings.ignore = ":disabled,:hidden";
                 return form.valid();
            },
            //onFinishing: function (event, currentIndex) {
            //    form.validate().settings.ignore = ":disabled";
            //    return form.valid();
            //},
            onStepChanged: function (event, currentIndex, priorIndex) {
                resizeJquerySteps();
               // form.validate().settings.ignore = ":disabled,:hidden";
                alert("yes");
               // return form.valid();
            },
            onFinished: function (event, currentIndex) {
                if ($("#TermsAgreed").is(':checked')) {
                    form.submit();
                } else { alert("Please accept term and condition") }
                //alert("Submitted!");
            }
        });
        resizeJquerySteps();
        //$('.datepicker').datetimepicker();
    });
    $(window).resize($.debounce(250, resizeJquerySteps));
</script>

Form

<div class="hud-form margin-bottom-70">
@Using Html.BeginForm("Submit", "Requests", Nothing, FormMethod.Post, New With {.id = "RequestStepsForm", .class = "hud-form"})
@Html.ValidationSummary(True)
@Html.HiddenFor(Function(m) m.Registration)
@Html.HiddenFor(Function(m) m.Manufacturer)
@Html.HiddenFor(Function(m) m.ModelName)
@
<div>
<h1>Account</h1>
<fieldset>
    <div class="hud-form-controls hud-form-section clearfix">
        <h6 class="hud-form-heading">ACCOUNT</h6>
        @If User.Identity.IsAuthenticated Then
        @
        <h6 style="padding:0 1em 0.5em">Hi @User.Identity.Name!</h6>
        Else
        @
        <p style="padding: 0 1em 0.5em; margin: 0">Either @Html.ActionLink("sign in", "Login", "Account") or @*@Html.ActionLink("register (full)", "Register", "Account")*@ register below to submit a quote.</p>
        @
        <div class="col-md-6 col-lg-4">
            <div>
                @Html.TextBoxFor(Function(model) model.User.FirstName, New With {.class = "full-width", .type = "text", .placeholder = "First Name"})
            </div>
        </div>
        @
        <div class="col-md-6 col-lg-4">
            <div>
                @Html.TextBoxFor(Function(model) model.User.LastName, New With {.class = "full-width", .placeholder = "Last Name", .type = "text"})
            </div>
        </div>
        @
        <div class="col-md-6 col-lg-4">
            <div>
                @Html.TextBoxFor(Function(model) model.User.PhoneNumber, New With {.class = "full-width", .type = "search", .placeholder = "Phone / Mobile"})
            </div>
        </div>
        @
        <div class="visible-lg clear"></div>
        @
        <div class="col-md-6 col-lg-4">
            <div>
                @Html.TextBoxFor(Function(model) model.User.Email, New With {.class = "full-width", .type = "search", .placeholder = "Email"})
            </div>
        </div>
        @
        <div class="col-md-6 col-lg-4">
            <div>
                @Html.TextBoxFor(Function(model) model.User.Password, New With {.class = "full-width", .type = "password", .placeholder = "Password"})
            </div>
        </div>
        @
        <div class="col-md-6 col-lg-4">
            <div>
                @Html.TextBoxFor(Function(model) model.User.ConfirmPassword, New With {.class = "full-width", .placeholder = "Confirm Password", .type = "password"})
            </div>
        </div>
        End If
    </div>
</fieldset>
Ram
  • 3,092
  • 10
  • 40
  • 56
Rakesh
  • 11
  • 2
  • You've included the ToolTipster plugin twice. The minified version contains the same code as the un-minified version... just pick one. – Sparky Feb 18 '15 at 21:20
  • Dear Sparky, I removed one of the plugin reference , but again same error hits at line errorPlacement: function (error, element) { **bold** $($("#divtool")).tooltipster('update', $(error).text()); $($("#divtool")).tooltipster('show'); } success: function (label, element) { $($("#divtool")).tooltipster('hide'); }, ......................It states update cannot be called on the uninitialized object.. Not sure if there is some compatibility issue? – Rakesh Feb 19 '15 at 06:38
  • If you're trying to follow [one of my ToolTipster integration questions](http://stackoverflow.com/questions/14741688/how-to-display-messages-from-jquery-validate-plugin-inside-of-tooltipster-toolti), then you're doing it all wrong. You cannot attach ToolTipster to the whole form object... you would attach it to each input element. Otherwise, have no idea what you're trying to do here, since you're showing us something with most of the relevant code commented out. – Sparky Feb 19 '15 at 15:22
  • Yes, I had referred those initialization steps. I have even tried on the individual form element initialization. Currently the form uses the HTML Helper "TextBoxFor" and this will render as below for FirstName and LastName – Rakesh Feb 20 '15 at 06:26
  • For the above I have tried to initialize as below without success $('#RequestStepsForm input[type="search"]').tooltipster({ trigger: 'custom', onlyOne: false, position: 'right' }); – Rakesh Feb 20 '15 at 06:55
  • If you're going to use ToolTipster on a form with jQuery Validate, then you need to understand that the `.tooltipster()` initialization method needs to be attached to ***every*** input element individually. You have not shown your attempt at this, nor have you shown the ***rendered*** HTML in your OP. – Sparky Feb 20 '15 at 15:18

0 Answers0