jquery - Dynamic form field on bootstrap -
i have looked many solutions couldn't exact solution bootstrap form.
i have code below. want put (+) next input field , adding new field (-) remove.
all examples done bootstrap not using form group. case form group. how can that?
i using bootstrap 3.3.6 version.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <div class="form-horizontal"> <div class="form-body"> <div class="form-group"> <label class="control-label col-md-3">pickup time</label> <div class="col-md-4"> <div class="input-group"> <input type="text" class="form-control"/> </div> <span class="help-block">enter pickup time </span> </div> </div> </div> <div class="form-actions right"> <div class="row"> <div class="col-md-offset-3 col-md-9"> <button type="button" class="btn btn-default prev-step">previous</button> <button type="button" class="btn default">cancel</button> <button type="button" class="btn btn-primary next-step blue"> <i class="fa fa-check"></i>save , continue </button> <button type="button" class="btn btn-primary next-step">next</button> </div> </div> </div> </div>
var template = '<div class="input-group"><input type="text" class="form-control"/></div>', minusbutton = '<span class="btn input-group-addon delete-field">(-)</span>'; $('.add-field').click(function() { var temp = $(template).insertbefore('.help-block'); temp.append(minusbutton); }); $('.fields').on('click', '.delete-field', function(){ $(this).parent().remove(); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <div class="form-horizontal"> <div class="form-body"> <div class="form-group"> <label class="control-label col-md-3">pickup time</label> <div class="col-md-4 fields"> <div class="input-group"> <input type="text" class="form-control"/> <span class="btn input-group-addon add-field">(+)</span> </div> <span class="help-block">enter pickup time </span> </div> </div> </div> <div class="form-actions right"> <div class="row"> <div class="col-md-offset-3 col-md-9"> <button type="button" class="btn btn-default prev-step">previous</button> <button type="button" class="btn default">cancel</button> <button type="button" class="btn btn-primary next-step blue"> <i class="fa fa-check"></i>save , continue </button> <button type="button" class="btn btn-primary next-step">next</button> </div> </div> </div> </div>
Comments
Post a Comment