content logo

Bootstrap Forms:

Bootstrap Dynamic Form with Add & Delete

The main purpose of a website form is to gather data. This data varies from simple credentials such as name and username to more sensitive information like credit card number. Nowadays, automated forms have taken a new form. Before, everything in a form must have been coded by a professional programmer but now, it is possible to create dynamic forms which is much easier to use for the people with not enough knowledge to design a form themselves via coding.

In this post, we have a code with Bootstrap dynamic input. The code allows you to add an automated form that can be easily customized to gather different data from the users. It’s nothing fancy but it definitely gets the job done. The code features a Bootstrap jQuery add delete input with which you can design different inputs for your users without having to put them in the code yourself. Bootstrap jQuery dynamic forms are the best solution for people who don’t have time for coding or simply lack the knowledge. It lets you add or delete whatever input you need to the form with much ease. Besides that, the code was professionally designed and is made in a way to adhere to search engine algorithms resulting in a higher SEO rank.

#Bootstrap Dynamic Input #Bootstrap JQuery Add Delete Input #Bootstrap JQuery Dynamic Form

<!-- This script got from www.frontendfreecode.com -->
<div id="app" class="container-fluid">
	<div class="col-xs-12">
		<div class="row  form-row" v-for="row in rows">
			<div class="col-xs-12">
				<div class="row">
					<div class="col-xs-12">
						<div class="col-xs-3">
							<select name="" id="" class="form-control" v-model="row.select">
								<option :value="option.value" v-for="option in options">{{ option.label }}</option>
							</select>
						</div>
						<div class="col-xs-6">
							<input type="text" class="form-control" placeholder="Value" v-model="row.name">
						</div>
						<div class="col-xs-2">
							<input type="checkbox" id="chk" v-model="row.check"><label for="chk">Mandatory</label>
						</div>
						<div class="col-xs-1">
							<button class="btn btn-danger" @click="deleteRow(row)">X</button>
						</div>
					</div>
				</div>
				<div class="row" v-if="row.select==3 || row.select==4 ">
					<div class="row subrow" v-for="subrow in row.subrows">
						<div class="col-xs-12">
							<div class="col-xs-3"></div>
							<div class="col-xs-7">
								<input type="text" class="form-control" v-model="subrow.answer">
							</div>
							<div class="col-xs-2">
								<button class="btn btn-danger" @click="deleteSubrow(row,subrow)">X</button>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-xs-12">
							<button class="btn btn-success center-block" @click="addSubRow(row)">Add Answer</button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-xs-12">
				<button type="submit" class="btn btn-info">Submit</button>
				<button type="submit" class="btn btn-success" @click="addRow">Add Row</button>
			</div>
		</div>
	</div>
</div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://www.frontendfreecode.com">Frontend Free Code</a>
                                                                            
.form-row {
	border:  1px solid #e2e2e2;
	margin:  10px;
	padding: 20px;
	background: #f2f2f2;
}
.subrow {
	margin: 5px;
	padding:  5px;
}
new Vue({
	el: '#app',
	data: {
		options: [
			{ 'label': 'Text', 'value': 1},
			{ 'label': 'Numeric', 'value': 2},
			{ 'label': 'Check box', 'value': 3},
			{ 'label': 'Radio button', 'value': 4},
			{ 'label': 'Drop down', 'value': 5},
			{ 'label': 'Image', 'value': 6},
			{ 'label': 'Date', 'value': 7},
		],
		rows: [
			{ 'select': 1, 'name': '', 'check': false, 'subrows': [{  answer: ''}]}
		]
	},
	methods: {
		addRow: function() {
			this.rows.push({'select': 1, 'name': '', 'check': false, subrows: [{ answer: ''} ]});
		},
		deleteRow: function(row) {
			this.rows.$remove(row);
		},
		addSubRow: function(row) {
			row.subrows.push({ answer: ''})
		},
		deleteSubrow: function(row, subrow) {
			row.subrows.$remove(subrow);
		}
	}
})
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from www.frontendfreecode.com -->

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.js"></script>
<style>
.form-row {
	border:  1px solid #e2e2e2;
	margin:  10px;
	padding: 20px;
	background: #f2f2f2;
}
.subrow {
	margin: 5px;
	padding:  5px;
}
</style>

</head>
<body>
<div id="app" class="container-fluid">
	<div class="col-xs-12">
		<div class="row  form-row" v-for="row in rows">
			<div class="col-xs-12">
				<div class="row">
					<div class="col-xs-12">
						<div class="col-xs-3">
							<select name="" id="" class="form-control" v-model="row.select">
								<option :value="option.value" v-for="option in options">{{ option.label }}</option>
							</select>
						</div>
						<div class="col-xs-6">
							<input type="text" class="form-control" placeholder="Value" v-model="row.name">
						</div>
						<div class="col-xs-2">
							<input type="checkbox" id="chk" v-model="row.check"><label for="chk">Mandatory</label>
						</div>
						<div class="col-xs-1">
							<button class="btn btn-danger" @click="deleteRow(row)">X</button>
						</div>
					</div>
				</div>
				<div class="row" v-if="row.select==3 || row.select==4 ">
					<div class="row subrow" v-for="subrow in row.subrows">
						<div class="col-xs-12">
							<div class="col-xs-3"></div>
							<div class="col-xs-7">
								<input type="text" class="form-control" v-model="subrow.answer">
							</div>
							<div class="col-xs-2">
								<button class="btn btn-danger" @click="deleteSubrow(row,subrow)">X</button>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-xs-12">
							<button class="btn btn-success center-block" @click="addSubRow(row)">Add Answer</button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-xs-12">
				<button type="submit" class="btn btn-info">Submit</button>
				<button type="submit" class="btn btn-success" @click="addRow">Add Row</button>
			</div>
		</div>
	</div>
</div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Frontend Free Code</a></div>
<script>
new Vue({
	el: '#app',
	data: {
		options: [
			{ 'label': 'Text', 'value': 1},
			{ 'label': 'Numeric', 'value': 2},
			{ 'label': 'Check box', 'value': 3},
			{ 'label': 'Radio button', 'value': 4},
			{ 'label': 'Drop down', 'value': 5},
			{ 'label': 'Image', 'value': 6},
			{ 'label': 'Date', 'value': 7},
		],
		rows: [
			{ 'select': 1, 'name': '', 'check': false, 'subrows': [{  answer: ''}]}
		]
	},
	methods: {
		addRow: function() {
			this.rows.push({'select': 1, 'name': '', 'check': false, subrows: [{ answer: ''} ]});
		},
		deleteRow: function(row) {
			this.rows.$remove(row);
		},
		addSubRow: function(row) {
			row.subrows.push({ answer: ''})
		},
		deleteSubrow: function(row, subrow) {
			row.subrows.$remove(subrow);
		}
	}
})
</script>

</body>
</html>
Preview