Question

I'm using jquery steps as a form wizard and I need to implement the autocomplete of jquery UI in a field inside the form wizard, but the autocomplete is not working, when I put the field out of the form, it works, this is the code that I use

<script>
 $(function (){


                    var availableTags = [""];
                   $("#wizard").on('keyup','.tags',function () {

                        $.post('LinkingPages', {Request : 'GetAirports',StartWith : $(this).val()}, function(data) {

                               var Tab = data.split(";");
                               var i;
                               for (i = 0; i < Tab.length; i++) {
                                      availableTags[i] = Tab[i];
                               }
                               for (var j = i; j < availableTags.length; j++) {
                                      availableTags[j]="";
                               }
                        },"text");

                 });

                    $('.tags').autocomplete({
                        open: function() {alert("Hello");},
                        source : availableTags

                 });

                     $("#wizard").steps({

                         headerTag: "h3",
                         bodyTag: "span",
                         transitionEffect: "slideLeft",

                         stepsOrientation: "vertical",
                           onStepChanging: function (event, currentIndex, newIndex)
                         {

                             $("#SendReqForm").validate().settings.ignore = ":disabled,:hidden";
                            return $("#SendReqForm").valid();
                         },
                         onFinishing: function (event, currentIndex)
                         {

                             $("#SendReqForm").validate().settings.ignore = ":disabled";
                             return $("#SendReqForm").valid();
                         },
                         onFinished: function (event, currentIndex)
                         {
                            $("#SendReqForm").submit();
                         }

                     });
                        function errorPlacement(error, element)
                    {
                        element.before(error);
                    }

                        $("#SendReqForm").validate({
                            //errorLabelContainer: '#errors',
                            errorPlacement: errorPlacement,
                            rules: {
                                Co_Password: {
                                    equalTo: "#password"
                                },
                                Co_Email: {
                                    equalToEmail: "#Email"
                                },
                                Password:{
                                    pwdComp:true

                                    }
                            }
                        });
                        jQuery.validator.addMethod("pwdComp", function(input,element, param) {
                            var reg = /^[^%\s]{6,}$/;
                            var reg2 = /[a-zA-Z]/;
                            var reg3 = /[0-9]/;

                            return reg.test(input) && reg2.test(input) && reg3.test(input);
                            },
                             jQuery.validator.format("For security reasons passwords must include a capital letter, small letter, number and be more than 6 characters."));




                });



        </script> 
Was it helpful?

Solution

I put the autocomplete code after the code of jquery steps and it works fine

OTHER TIPS

Declare Jquery steps configuration before the autocomplete. This works for me:

HTML

<form id="example-form" action="#">
            <div>
                <h3>@Resources.Filter</h3>
                <section>

                    <div class="row">
                        <div class="col-md-12">
                            <div class="col-md-12">
                                <input type="text" style="margin: 15px 0px; font-size: 16px; color: #777; text-transform: uppercase;" class="form-control" id="academiaInput" placeholder="@Resources.TypeSearchForGym..." />
                            </div>

                        </div>
                    </div>


                </section>
                <h3>Profile</h3>
                <section>

                </section>
                <h3>Hints</h3>
                <section>

                </section>
                <h3>Finish</h3>
                <section>

                </section>
            </div>
        </form>

Javascript

$(document).ready(function () {

    var form = $("#example-form");

    form.children("div").steps({
        headerTag: "h3",
        bodyTag: "section",
        transitionEffect: "slideLeft",
        onStepChanging: function (event, currentIndex, newIndex) {
            form.validate().settings.ignore = ":disabled,:hidden";
            return form.valid();
        },
        onFinishing: function (event, currentIndex) {
            form.validate().settings.ignore = ":disabled";
            return form.valid();
        },
        onFinished: function (event, currentIndex) {
            alert("Submitted!");
        }
    });

    $("#academiaInput").autocomplete({
        minLength: 1,
        source: function (request, response) {
            $.ajax({
                MY AJAX TO AUTOCOMPLETE
            })
        },
        select: function (event, ui) {
            event.preventDefault();
            $("#academiaInput").val(ui.item.label);

        },
        change: function (event, ui) {

        }
    })
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top