Created
January 11, 2017 12:48
-
-
Save manojchowrasiya/1615b27c47ec6fa8341f858822048085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- http://bootsnipp.com/snippets/8AGX3 --> | |
<!-- http://bootsnipp.com/snippets/featured/form-wizard-and-validation --> | |
<!-- https://www.codeply.com/go/RsUnW5kOcs#! --> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-8 col-md-offset-2"> | |
<div class="panel panel-default"> | |
<div class="panel-heading">Dashboard</div> | |
<div class="panel-body"> | |
<div class="stepwizard"> | |
<div class="stepwizard-row setup-panel"> | |
<div class="stepwizard-step"> | |
<a href="#step-1" type="button" class="btn btn-primary btn-circle">1</a> | |
<p>Step 1</p> | |
</div> | |
<div class="stepwizard-step"> | |
<a href="#step-2" type="button" class="btn btn-default btn-circle" disabled="disabled">2</a> | |
<p>Step 2</p> | |
</div> | |
<div class="stepwizard-step"> | |
<a href="#step-3" type="button" class="btn btn-default btn-circle" disabled="disabled">3</a> | |
<p>Step 3</p> | |
</div> | |
<div class="stepwizard-step"> | |
<a href="#step-4" type="button" class="btn btn-default btn-circle" disabled="disabled">4</a> | |
<p>Step 4</p> | |
</div> | |
</div> | |
</div> | |
<form role="form"> | |
<div class="row setup-content" id="step-1"> | |
<div class="col-xs-12"> | |
<div class="col-md-12"> | |
<h3> Step 1</h3> | |
<div class="form-group"> | |
<label class="control-label">Select Box</label> | |
<select class="form-control selectpicker" required="required"> | |
<option></option> | |
<option>Hot Dog, Fries and a Soda</option> | |
<option>Burger, Shake and a Smile</option> | |
<option>Sugar, Spice and all things nice</option> | |
</select> | |
</div> | |
<div class="form-group"> | |
<label class="control-label">First Name</label> | |
<input maxlength="100" type="text" required="required" class="form-control" placeholder="Enter First Name" /> | |
</div> | |
<div class="form-group"> | |
<label class="control-label">Last Name</label> | |
<input maxlength="100" type="text" required="required" class="form-control" placeholder="Enter Last Name" /> | |
</div> | |
<button class="btn btn-primary nextBtn btn-lg pull-right" type="button" >Next</button> | |
</div> | |
</div> | |
</div> | |
<div class="row setup-content" id="step-2"> | |
<div class="col-xs-12"> | |
<div class="col-md-12"> | |
<h3> Step 2</h3> | |
<div class="form-group"> | |
<label class="control-label">Company Name</label> | |
<input maxlength="200" type="text" required="required" class="form-control" placeholder="Enter Company Name" /> | |
</div> | |
<div class="form-group"> | |
<label class="control-label">Company Address</label> | |
<input maxlength="200" type="text" required="required" class="form-control" placeholder="Enter Company Address" /> | |
</div> | |
<button class="btn btn-primary prevBtn btn-lg pull-left" type="button" >Previous</button> | |
<button class="btn btn-primary nextBtn btn-lg pull-right" type="button" >Next</button> | |
</div> | |
</div> | |
</div> | |
<div class="row setup-content" id="step-3"> | |
<div class="col-xs-12"> | |
<div class="col-md-12"> | |
<h3> Step 3</h3> | |
<div class="form-group"> | |
<label class="control-label">Company Address</label> | |
<input maxlength="200" type="text" required="required" class="form-control" placeholder="Enter Company Address" /> | |
</div> | |
<button class="btn btn-primary prevBtn btn-lg pull-left" type="button" >Previous</button> | |
<button class="btn btn-primary nextBtn btn-lg pull-right" type="button" >Next</button> | |
<!-- <button class="btn btn-success btn-lg pull-right" type="submit">Finish!</button> --> | |
</div> | |
</div> | |
</div> | |
<div class="row setup-content" id="step-4"> | |
<div class="col-xs-12"> | |
<div class="col-md-12"> | |
<h3> Step 4</h3> | |
<button class="btn btn-primary prevBtn btn-lg pull-left" type="button" >Previous</button> | |
<button class="btn btn-success btn-lg pull-right" type="submit">Finish!</button> | |
</div> | |
</div> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<style type="text/css"> | |
.stepwizard-step p { | |
margin-top: 10px; | |
} | |
.stepwizard-row { | |
display: table-row; | |
} | |
.stepwizard { | |
display: table; | |
width: 100%; | |
position: relative; | |
} | |
.stepwizard-step button[disabled] { | |
opacity: 1 !important; | |
filter: alpha(opacity=100) !important; | |
} | |
.stepwizard-row:before { | |
top: 14px; | |
bottom: 0; | |
position: absolute; | |
content: " "; | |
width: 100%; | |
height: 1px; | |
background-color: #ccc; | |
z-order: 0; | |
} | |
.stepwizard-step { | |
display: table-cell; | |
text-align: center; | |
position: relative; | |
} | |
.btn-circle { | |
width: 30px; | |
height: 30px; | |
text-align: center; | |
padding: 6px 0; | |
font-size: 12px; | |
line-height: 1.428571429; | |
border-radius: 15px; | |
} | |
</style> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function () { | |
var navListItems = $('div.setup-panel div a'), | |
allWells = $('.setup-content'), | |
allNextBtn = $('.nextBtn'), | |
allPrevBtn = $('.prevBtn'); | |
allWells.hide(); | |
navListItems.click(function (e) { | |
e.preventDefault(); | |
var $target = $($(this).attr('href')), | |
$item = $(this); | |
if($(this).attr('disabled')){ | |
return false; | |
} | |
if (!$item.hasClass('disabled')) { | |
navListItems.removeClass('btn-primary').addClass('btn-default'); | |
$item.addClass('btn-primary'); | |
// $item.addAttr('disabled','disabled'); | |
allWells.hide(); | |
$target.show(); | |
$target.find('input:eq(0)').focus(); | |
} | |
var curStepBtn = $(this).attr('href'); | |
console.log(curStepBtn); | |
var numItems = $('.stepwizard-row .stepwizard-step').length; | |
var get_counter = curStepBtn.replace('#step-', ''); | |
for(var stepCounter=get_counter; stepCounter<=numItems; stepCounter++){ | |
$('div.setup-panel div a[href="#step-' + stepCounter + '"]').parent().next().children("a").attr("disabled", "disabled"); | |
} | |
}); | |
// $('div.setup-panel div a').attr("disabled", "disabled"); | |
allPrevBtn.click(function(){ | |
var curStep = $(this).closest(".setup-content"), | |
curStepBtn = curStep.attr("id"), | |
prevStepWizard = $('div.setup-panel div a[href="#' + curStepBtn + '"]').parent().prev().children("a"); | |
prevStepWizard.removeAttr('disabled').trigger('click'); | |
}); | |
allNextBtn.click(function(){ | |
var curStep = $(this).closest(".setup-content"), | |
curStepBtn = curStep.attr("id"), | |
nextStepWizard = $('div.setup-panel div a[href="#' + curStepBtn + '"]').parent().next().children("a"), | |
// previousStepWizard = $('div.setup-panel div a[href="#' + curStepBtn + '"]').parent().nextAll('stepwizard-step').children("a"), | |
curInputs = curStep.find("input[type='text'],input[type='url'],select"), | |
isValid = true; | |
console.log("allNextBtn : "+curStepBtn); | |
$(".form-group").removeClass("has-error"); | |
for(var i=0; i<curInputs.length; i++){ | |
if (!curInputs[i].validity.valid){ | |
isValid = false; | |
$(curInputs[i]).closest(".form-group").addClass("has-error"); | |
} | |
} | |
if (isValid){ | |
nextStepWizard.removeAttr('disabled').trigger('click'); | |
// previousStepWizard.addAttr("disabled", "disabled"); | |
} | |
}); | |
$('div.setup-panel div a.btn-primary').trigger('click'); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment