Linear Stepper Reset Method


Topic: Linear Stepper Reset Method

Gassner asked 4 years ago

Hey there, i use linear stepper in one of my forms. The problem is, i want to reset the stepper and all inputs in it after ajax post is successfull.

i didn't find anything usefull in your docs. Can anyone help me?


Gassner answered 4 years ago

Found a Solutions:

  (function( $ ){
            $.fn.resetStepper = function() {
                /* Get MDB Stepper */
                var myStepper = this;
                /* Get Steps */
                var mySteps = myStepper.find("li");

                /* Loop Steps */
                $( mySteps ).each(function( index ) {
                    /* Step Element */
                    var stepElement = this;
                    var stepContent = $(stepElement).find(".step-new-content");

                    /* if Element has Class step */
                    if ($(stepElement).hasClass("step")){
                        /* Select First Element */
                        if (index === 0 || index === "0"){
                            $(stepElement).removeClass("wrong").removeClass("done").addClass("active");
                            $(stepContent).css("display","block");
                        }else{
                            $(stepElement).removeClass("wrong").removeClass("done").removeClass("active");
                            $(stepContent).css("display","none");
                        }
                        /* Reset Inputs */
                        var inputs = $(stepContent).find("input");
                        $(inputs).each(function (index){
                           var myInput = this;
                           $(myInput).val("");
                        });
                    }

                });
            };
        })( jQuery );

Then Call

 $("#postingAddStepper").resetStepper();

Marcin Luczak staff answered 4 years ago

Hello,

I'm glad that you have found a suitable solution for your question.

Best regards, Marcin


FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Closed

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.19.1
  • Device: PC
  • Browser: Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No