Angular Builder Form

Developer
Size
2,788 Kb
Views
24,288

How do I make an angular builder form?

What is a angular builder form? How do you make a angular builder form? This script and codes were developed by VULE on 26 October 2022, Wednesday.

Angular Builder Form Previews

Angular Builder Form - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Angular Builder Form</title> <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css'>
</head>
<body> <div class="row" ng-app="myapp"> <div class="col-md-6 col-md-offset-3"> <h1>Form Builder</h1> <form-builder-component /> </div>
<script type="text/ng-template" id="form-builder.html">
<div class="box-widget box"> <div class="box-header with-border"> <h3 class="box-title">All Employees</h3> <div class="box-tools pull-right"> <button ng-click="$ctrl.save()" class="btn btn-primary btn-small"> Save Form </button> </div> </div> <div class="box-body"> <div class="form-group"> <label>Form Name</label> <input type="text" ng-model="$ctrl.form.name" class="form-control" /> </div> <div class="form-group"> <div class="form-inline"> <select class="form-control" ng-model="$ctrl.form.field"> <option value="">Choose Field</option> <option value="text">Text</option> <option value="dropdown">Dropdown</option> <option value="upload">Upload File</option> </select> <button class="btn btn-primary" ng-click="$ctrl.addField()">Add Field</button> </div> </div> <div ng-repeat="item in $ctrl.list track by $index"> <form-builder-text ng-if="item.type=='text'" ng-model="$ctrl.list[$index]" index="$index" on-delete="$ctrl.deleteItem($event)" /> <form-builder-dropdown ng-if="item.type=='dropdown'" ng-model="$ctrl.list[$index]" index="$index" on-delete="$ctrl.deleteItem($event)" /> </div> </div>
</div>
</script>
<script type="text/ng-template" id="form-builder-text.html">
<div class="box box-default"> <div class="box-heading"> <h3 class="box-title">Panel title</h3> </div> <div class="box-body"> <div class="form-group"> <label for="">Label</label> <input type="text" class="form-control" ng-model="$ctrl.item.label"/> </div> </div> <div class="box-footer"> <button class="btn btn-danger" ng-click="$ctrl.delete()">Delete</button> </div>
</div>
</script>
<script type="text/ng-template" id="form-builder-dropdown.html">
<div class="box box-default"> <div class="box-heading"> <h3 class="box-title">Panel title</h3> </div> <div class="box-body"> <div class="form-group"> <label for="">Label</label> <input type="text" class="form-control" ng-model="$ctrl.item.label"/> </div> {{ $ctrl.item.options | json }} <label for="">Options</label> <div class="form-group" ng-repeat="option in $ctrl.item.options track by $index"> <div class="form-inline"> <input type="text" class="form-control" ng-model="$ctrl.item.options[$index]"/> <a class="text text-danger" style="cursor: pointer;" ng-click="$ctrl.deleteOption($index)">Del option</a> </div> </div> </div> <div class="box-footer"> <a class="text text-primary" style="cursor: pointer;" ng-click="$ctrl.addOption()">Add option</a> <button class="btn btn-danger" ng-click="$ctrl.delete()">Delete</button> </div>
</div>
</script>
</div> <script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Angular Builder Form - Script Codes JS Codes

var app = angular.module("myapp", []);
app.component("formBuilderComponent", { bindings: { onSave: '&', list: '<', form: '<' }, templateUrl: "form-builder.html", controller: function($element, $window) { var scope = this; scope.$onInit = function() { if(!scope.list) scope.list = []; if(! scope.form) scope.form = { name: "Form Name", field: null }; }; scope.save = function() { if(scope.onSave) scope.onSave({ $event: { list: scope.list, form: scope.form } }); } scope.addField = function() { switch (scope.form.field) { case "text": scope.list.push({ type: 'text', label: 'text label' }); break; case "dropdown": scope.list.push({ type: 'dropdown', label: 'dropdown label', options : [] }) break; } }; scope.deleteItem = function(event) { if($window.confirm('Confirm Delete?')) scope.list.splice(event.index, 1); } }
});
app.component("formBuilderText", { templateUrl: "form-builder-text.html", bindings: { item: "=ngModel", index: '<', onDelete: '&' }, controller: function() { var scope = this; scope.$onInit = function() { if(!scope.item) scope.item = { label: "text label", type: 'text' }; }; scope.delete = function(event) { scope.onDelete({ $event: { index: angular.copy(scope.index) } }); } }
});
app.component("formBuilderDropdown", { templateUrl: "form-builder-dropdown.html", bindings: { item: "=ngModel", index: '<', onDelete: '&' }, controller: function() { var scope = this; scope.$onInit = function() { if(!scope.item) scope.item = { label: "text label", type: 'dropdown', options: [] }; }; scope.addOption = function() { scope.item.options.push(""); } scope.deleteOption = function(index) { scope.item.options.splice(index, 1); } scope.delete = function(event) { scope.onDelete({ $event: { index: angular.copy(scope.index) } }); } }
});
Angular Builder Form - Script Codes
Angular Builder Form - Script Codes
Home Page Home
Developer VULE
Username tinsatthu4
Uploaded October 26, 2022
Rating 3
Size 2,788 Kb
Views 24,288
Do you need developer help for Angular Builder Form?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

VULE (tinsatthu4) Script Codes
Create amazing SEO content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!