"Multiple fields"
Bootstrap 3.3.0 Snippet by effa

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <div class="col-xs-6"> <form> <div class="form-group multiple-form-group"> <label>Multiple selects</label> <div class="form-group input-group"> <select name="multiple[]" class="form-control"> <option value="">Default select</option> <option value="">Option 1</option> <option value="">Option 2</option> </select> <span class="input-group-btn"><button type="button" class="btn btn-default btn-add">+ </button></span> </div> </div> </form> </div> </div> </div>
(function ($) { $(function () { var addFormGroup = function (event) { event.preventDefault(); var $formGroup = $(this).closest('.form-group'); var $multipleFormGroup = $formGroup.closest('.multiple-form-group'); var $formGroupClone = $formGroup.clone(); $(this) .toggleClass('btn-default btn-add btn-danger btn-remove') .html('–'); $formGroupClone.find('input').val(''); $formGroupClone.insertAfter($formGroup); var $lastFormGroupLast = $multipleFormGroup.find('.form-group:last'); if ($multipleFormGroup.data('max') <= countFormGroup($multipleFormGroup)) { $lastFormGroupLast.find('.btn-add').attr('disabled', true); } }; var removeFormGroup = function (event) { event.preventDefault(); var $formGroup = $(this).closest('.form-group'); var $multipleFormGroup = $formGroup.closest('.multiple-form-group'); var $lastFormGroupLast = $multipleFormGroup.find('.form-group:last'); if ($multipleFormGroup.data('max') >= countFormGroup($multipleFormGroup)) { $lastFormGroupLast.find('.btn-add').attr('disabled', false); } $formGroup.remove(); }; var countFormGroup = function ($form) { return $form.find('.form-group').length; }; $(document).on('click', '.btn-add', addFormGroup); $(document).on('click', '.btn-remove', removeFormGroup); }); })(jQuery);

Related: See More


Questions / Comments: