Howto handle multiple check boxes data in angularJS dynamic forms
I have added form dynamically from my web API and i am confused about how to get check boxes selected data
codepen
dynamic.form
<form name="myForm" class="form-horizontal" role="form" ng-submit="submitForm()">
<div ng-repeat="field in entity.fields">
<ng-form name="form">
<!-- TEXT FIELDS -->
<div ng-if="field.type=='text'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$dirty && form[field.name].$error.required,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<input type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
class="form-control" required />
<p class="help-block" ng-show="form[field.name].$dirty && form[field.name].$error.required">{{field.name}}
is required</p>
<!-- <p class="help-block" ng-show="{{'form.'+field.name+'.$dirty && form.'+field.name+'.$error.required'}}">required</p> -->
</div>
</div>
<!-- EMAIL FIELDS -->
<div ng-if="field.type=='email'" class="form-group" ng-class="{ 'has-error' :
((form[field.name].$dirty && form[field.name].$error.required) || (form[field.name].$error.email)),
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<input type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
class="form-control" required />
<span class="help-block" ng-show="form[field.name].$dirty && form[field.name].$error.required">{{field.name}}
is required</span>
<span class="help-block" ng-show="!form[field.name].$error.required && form[field.name].$error.email">Please
enter valid {{field.name}}</span>
<!-- <p class="help-block" ng-show="{{'form.'+field.name+'.$dirty && form.'+field.name+'.$error.required'}}">required</p> -->
</div>
</div>
<!-- PASSWORD FIELDS -->
<div ng-if="field.type=='password'" class="form-group" ng-class="{ 'has-error' :
((form[field.name].$dirty && form[field.name].$error.required) || (form[field.name].$error.minlength || form[field.name].$error.maxlength)),
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<input type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
ng-minlength={{field.min}} ng-maxlength={{field.max}} class="form-control" required />
<p class="help-block" ng-show="form[field.name].$dirty && form[field.name].$error.required">{{field.name}}
is required</p>
<p class="help-block" ng-show="!form[field.name].$error.required && (form[field.name].$error.minlength || form[field.name].$error.maxlength)">Passwords
must be between 8 and 20 characters</p>
</div>
</div>
<!-- SELECT FIELDS -->
<div ng-if="field.type=='select'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$invalid && form[field.name].$touched,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<select type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
class="form-control" required>
<option value=''>Select Department</option>
<option ng-repeat="field in field.options" value="{{field.name}}">
{{field.name}}
</option>
</select>
<p class="help-block" ng-show="form[field.name].$invalid && form[field.name].$touched">{{field.name}}
is required</p>
</div>
</div>
<!-- RADIO BUTTONS -->
<div ng-if="field.type=='radio'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$invalid && form[field.name].$touched,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">Clouds</label>
<div class="col-sm-6">
<label class="radio-inline" ng-repeat="option in field.options">
<input type="radio" ng-model="field.data" name="taskGroup" id="{{option.name}}" value="{{option.id}}">
{{option.name}}
</label>
</div>
</div>
<!-- CHECK BOXES -->
<div ng-if="field.type=='checkbox'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$invalid && form[field.name].$touched,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">Clouds</label>
<div class="col-sm-6">
<label class="checkbox-inline" ng-repeat="option in field.options">
<input type="checkbox" ng-model="field.data" name="taskGroup" id="{{option.name}}" value="{{option.id}}">
{{option.name}}
</label>
</div>
</div>
</ng-form>
</div>
<br />
<button ng-disabled="myForm.$invalid" type="submit" id="submit">Submit</button>
<br />
</form>
{{entity|json}}
Controller
routerApp.controller('DynamicController1', ['$scope', function ($scope) {
// we would get this from the api
$scope.entity = {
name: "Course",
fields:
[
{ type: "text", name: "firstname", label: "Name", required: true, data: "" },
{ type: "radio", name: "color_id", label: "Colors", options: [{ id: 1, name: "orange" }, { id: 2, name: "pink" }, { id: 3, name: "gray" }, { id: 4, name: "cyan" }], required: true, data: "" },
{ type: "email", name: "emailUser", label: "Email", required: true, data: "" },
{ type: "text", name: "city", label: "City", required: true, data: "" },
{ type: "password", name: "pass", label: "Password", min: 6, max: 20, required: true, data: "" },
{ type: "select", name: "teacher_id", label: "Teacher", options: [{ name: "Mark" }, { name: "Claire" }, { name: "Daniel" }, { name: "Gary" }], required: true, data: "" },
{ type: "checkbox", name: "car_id", label: "Cars", options: [{ id: 1, name: "bmw" }, { id: 2, name: "audi" }, { id: 3, name: "porche" }, { id: 4, name: "jaguar" }], required: true, data: "" }
]
};
$scope.submitForm = function () {
$log.debug($scope.entity);
}
}]);
routerApp.directive("dynamicName",function($compile){
return {
restrict:"A",
terminal:true,
priority:1000,
link:function(scope,element,attrs){
element.attr('name', scope.$eval(attrs.dynamicName));
element.removeAttr("dynamic-name");
$compile(element)(scope);
}
}
})
angularjs
add a comment |
I have added form dynamically from my web API and i am confused about how to get check boxes selected data
codepen
dynamic.form
<form name="myForm" class="form-horizontal" role="form" ng-submit="submitForm()">
<div ng-repeat="field in entity.fields">
<ng-form name="form">
<!-- TEXT FIELDS -->
<div ng-if="field.type=='text'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$dirty && form[field.name].$error.required,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<input type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
class="form-control" required />
<p class="help-block" ng-show="form[field.name].$dirty && form[field.name].$error.required">{{field.name}}
is required</p>
<!-- <p class="help-block" ng-show="{{'form.'+field.name+'.$dirty && form.'+field.name+'.$error.required'}}">required</p> -->
</div>
</div>
<!-- EMAIL FIELDS -->
<div ng-if="field.type=='email'" class="form-group" ng-class="{ 'has-error' :
((form[field.name].$dirty && form[field.name].$error.required) || (form[field.name].$error.email)),
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<input type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
class="form-control" required />
<span class="help-block" ng-show="form[field.name].$dirty && form[field.name].$error.required">{{field.name}}
is required</span>
<span class="help-block" ng-show="!form[field.name].$error.required && form[field.name].$error.email">Please
enter valid {{field.name}}</span>
<!-- <p class="help-block" ng-show="{{'form.'+field.name+'.$dirty && form.'+field.name+'.$error.required'}}">required</p> -->
</div>
</div>
<!-- PASSWORD FIELDS -->
<div ng-if="field.type=='password'" class="form-group" ng-class="{ 'has-error' :
((form[field.name].$dirty && form[field.name].$error.required) || (form[field.name].$error.minlength || form[field.name].$error.maxlength)),
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<input type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
ng-minlength={{field.min}} ng-maxlength={{field.max}} class="form-control" required />
<p class="help-block" ng-show="form[field.name].$dirty && form[field.name].$error.required">{{field.name}}
is required</p>
<p class="help-block" ng-show="!form[field.name].$error.required && (form[field.name].$error.minlength || form[field.name].$error.maxlength)">Passwords
must be between 8 and 20 characters</p>
</div>
</div>
<!-- SELECT FIELDS -->
<div ng-if="field.type=='select'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$invalid && form[field.name].$touched,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<select type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
class="form-control" required>
<option value=''>Select Department</option>
<option ng-repeat="field in field.options" value="{{field.name}}">
{{field.name}}
</option>
</select>
<p class="help-block" ng-show="form[field.name].$invalid && form[field.name].$touched">{{field.name}}
is required</p>
</div>
</div>
<!-- RADIO BUTTONS -->
<div ng-if="field.type=='radio'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$invalid && form[field.name].$touched,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">Clouds</label>
<div class="col-sm-6">
<label class="radio-inline" ng-repeat="option in field.options">
<input type="radio" ng-model="field.data" name="taskGroup" id="{{option.name}}" value="{{option.id}}">
{{option.name}}
</label>
</div>
</div>
<!-- CHECK BOXES -->
<div ng-if="field.type=='checkbox'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$invalid && form[field.name].$touched,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">Clouds</label>
<div class="col-sm-6">
<label class="checkbox-inline" ng-repeat="option in field.options">
<input type="checkbox" ng-model="field.data" name="taskGroup" id="{{option.name}}" value="{{option.id}}">
{{option.name}}
</label>
</div>
</div>
</ng-form>
</div>
<br />
<button ng-disabled="myForm.$invalid" type="submit" id="submit">Submit</button>
<br />
</form>
{{entity|json}}
Controller
routerApp.controller('DynamicController1', ['$scope', function ($scope) {
// we would get this from the api
$scope.entity = {
name: "Course",
fields:
[
{ type: "text", name: "firstname", label: "Name", required: true, data: "" },
{ type: "radio", name: "color_id", label: "Colors", options: [{ id: 1, name: "orange" }, { id: 2, name: "pink" }, { id: 3, name: "gray" }, { id: 4, name: "cyan" }], required: true, data: "" },
{ type: "email", name: "emailUser", label: "Email", required: true, data: "" },
{ type: "text", name: "city", label: "City", required: true, data: "" },
{ type: "password", name: "pass", label: "Password", min: 6, max: 20, required: true, data: "" },
{ type: "select", name: "teacher_id", label: "Teacher", options: [{ name: "Mark" }, { name: "Claire" }, { name: "Daniel" }, { name: "Gary" }], required: true, data: "" },
{ type: "checkbox", name: "car_id", label: "Cars", options: [{ id: 1, name: "bmw" }, { id: 2, name: "audi" }, { id: 3, name: "porche" }, { id: 4, name: "jaguar" }], required: true, data: "" }
]
};
$scope.submitForm = function () {
$log.debug($scope.entity);
}
}]);
routerApp.directive("dynamicName",function($compile){
return {
restrict:"A",
terminal:true,
priority:1000,
link:function(scope,element,attrs){
element.attr('name', scope.$eval(attrs.dynamicName));
element.removeAttr("dynamic-name");
$compile(element)(scope);
}
}
})
angularjs
add a comment |
I have added form dynamically from my web API and i am confused about how to get check boxes selected data
codepen
dynamic.form
<form name="myForm" class="form-horizontal" role="form" ng-submit="submitForm()">
<div ng-repeat="field in entity.fields">
<ng-form name="form">
<!-- TEXT FIELDS -->
<div ng-if="field.type=='text'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$dirty && form[field.name].$error.required,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<input type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
class="form-control" required />
<p class="help-block" ng-show="form[field.name].$dirty && form[field.name].$error.required">{{field.name}}
is required</p>
<!-- <p class="help-block" ng-show="{{'form.'+field.name+'.$dirty && form.'+field.name+'.$error.required'}}">required</p> -->
</div>
</div>
<!-- EMAIL FIELDS -->
<div ng-if="field.type=='email'" class="form-group" ng-class="{ 'has-error' :
((form[field.name].$dirty && form[field.name].$error.required) || (form[field.name].$error.email)),
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<input type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
class="form-control" required />
<span class="help-block" ng-show="form[field.name].$dirty && form[field.name].$error.required">{{field.name}}
is required</span>
<span class="help-block" ng-show="!form[field.name].$error.required && form[field.name].$error.email">Please
enter valid {{field.name}}</span>
<!-- <p class="help-block" ng-show="{{'form.'+field.name+'.$dirty && form.'+field.name+'.$error.required'}}">required</p> -->
</div>
</div>
<!-- PASSWORD FIELDS -->
<div ng-if="field.type=='password'" class="form-group" ng-class="{ 'has-error' :
((form[field.name].$dirty && form[field.name].$error.required) || (form[field.name].$error.minlength || form[field.name].$error.maxlength)),
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<input type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
ng-minlength={{field.min}} ng-maxlength={{field.max}} class="form-control" required />
<p class="help-block" ng-show="form[field.name].$dirty && form[field.name].$error.required">{{field.name}}
is required</p>
<p class="help-block" ng-show="!form[field.name].$error.required && (form[field.name].$error.minlength || form[field.name].$error.maxlength)">Passwords
must be between 8 and 20 characters</p>
</div>
</div>
<!-- SELECT FIELDS -->
<div ng-if="field.type=='select'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$invalid && form[field.name].$touched,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<select type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
class="form-control" required>
<option value=''>Select Department</option>
<option ng-repeat="field in field.options" value="{{field.name}}">
{{field.name}}
</option>
</select>
<p class="help-block" ng-show="form[field.name].$invalid && form[field.name].$touched">{{field.name}}
is required</p>
</div>
</div>
<!-- RADIO BUTTONS -->
<div ng-if="field.type=='radio'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$invalid && form[field.name].$touched,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">Clouds</label>
<div class="col-sm-6">
<label class="radio-inline" ng-repeat="option in field.options">
<input type="radio" ng-model="field.data" name="taskGroup" id="{{option.name}}" value="{{option.id}}">
{{option.name}}
</label>
</div>
</div>
<!-- CHECK BOXES -->
<div ng-if="field.type=='checkbox'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$invalid && form[field.name].$touched,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">Clouds</label>
<div class="col-sm-6">
<label class="checkbox-inline" ng-repeat="option in field.options">
<input type="checkbox" ng-model="field.data" name="taskGroup" id="{{option.name}}" value="{{option.id}}">
{{option.name}}
</label>
</div>
</div>
</ng-form>
</div>
<br />
<button ng-disabled="myForm.$invalid" type="submit" id="submit">Submit</button>
<br />
</form>
{{entity|json}}
Controller
routerApp.controller('DynamicController1', ['$scope', function ($scope) {
// we would get this from the api
$scope.entity = {
name: "Course",
fields:
[
{ type: "text", name: "firstname", label: "Name", required: true, data: "" },
{ type: "radio", name: "color_id", label: "Colors", options: [{ id: 1, name: "orange" }, { id: 2, name: "pink" }, { id: 3, name: "gray" }, { id: 4, name: "cyan" }], required: true, data: "" },
{ type: "email", name: "emailUser", label: "Email", required: true, data: "" },
{ type: "text", name: "city", label: "City", required: true, data: "" },
{ type: "password", name: "pass", label: "Password", min: 6, max: 20, required: true, data: "" },
{ type: "select", name: "teacher_id", label: "Teacher", options: [{ name: "Mark" }, { name: "Claire" }, { name: "Daniel" }, { name: "Gary" }], required: true, data: "" },
{ type: "checkbox", name: "car_id", label: "Cars", options: [{ id: 1, name: "bmw" }, { id: 2, name: "audi" }, { id: 3, name: "porche" }, { id: 4, name: "jaguar" }], required: true, data: "" }
]
};
$scope.submitForm = function () {
$log.debug($scope.entity);
}
}]);
routerApp.directive("dynamicName",function($compile){
return {
restrict:"A",
terminal:true,
priority:1000,
link:function(scope,element,attrs){
element.attr('name', scope.$eval(attrs.dynamicName));
element.removeAttr("dynamic-name");
$compile(element)(scope);
}
}
})
angularjs
I have added form dynamically from my web API and i am confused about how to get check boxes selected data
codepen
dynamic.form
<form name="myForm" class="form-horizontal" role="form" ng-submit="submitForm()">
<div ng-repeat="field in entity.fields">
<ng-form name="form">
<!-- TEXT FIELDS -->
<div ng-if="field.type=='text'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$dirty && form[field.name].$error.required,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<input type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
class="form-control" required />
<p class="help-block" ng-show="form[field.name].$dirty && form[field.name].$error.required">{{field.name}}
is required</p>
<!-- <p class="help-block" ng-show="{{'form.'+field.name+'.$dirty && form.'+field.name+'.$error.required'}}">required</p> -->
</div>
</div>
<!-- EMAIL FIELDS -->
<div ng-if="field.type=='email'" class="form-group" ng-class="{ 'has-error' :
((form[field.name].$dirty && form[field.name].$error.required) || (form[field.name].$error.email)),
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<input type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
class="form-control" required />
<span class="help-block" ng-show="form[field.name].$dirty && form[field.name].$error.required">{{field.name}}
is required</span>
<span class="help-block" ng-show="!form[field.name].$error.required && form[field.name].$error.email">Please
enter valid {{field.name}}</span>
<!-- <p class="help-block" ng-show="{{'form.'+field.name+'.$dirty && form.'+field.name+'.$error.required'}}">required</p> -->
</div>
</div>
<!-- PASSWORD FIELDS -->
<div ng-if="field.type=='password'" class="form-group" ng-class="{ 'has-error' :
((form[field.name].$dirty && form[field.name].$error.required) || (form[field.name].$error.minlength || form[field.name].$error.maxlength)),
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<input type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
ng-minlength={{field.min}} ng-maxlength={{field.max}} class="form-control" required />
<p class="help-block" ng-show="form[field.name].$dirty && form[field.name].$error.required">{{field.name}}
is required</p>
<p class="help-block" ng-show="!form[field.name].$error.required && (form[field.name].$error.minlength || form[field.name].$error.maxlength)">Passwords
must be between 8 and 20 characters</p>
</div>
</div>
<!-- SELECT FIELDS -->
<div ng-if="field.type=='select'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$invalid && form[field.name].$touched,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">{{field.label}}</label>
<div class="col-sm-6">
<select type="{{ field.type }}" dynamic-name="field.name" id="{{field.name}}" ng-model="field.data"
class="form-control" required>
<option value=''>Select Department</option>
<option ng-repeat="field in field.options" value="{{field.name}}">
{{field.name}}
</option>
</select>
<p class="help-block" ng-show="form[field.name].$invalid && form[field.name].$touched">{{field.name}}
is required</p>
</div>
</div>
<!-- RADIO BUTTONS -->
<div ng-if="field.type=='radio'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$invalid && form[field.name].$touched,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">Clouds</label>
<div class="col-sm-6">
<label class="radio-inline" ng-repeat="option in field.options">
<input type="radio" ng-model="field.data" name="taskGroup" id="{{option.name}}" value="{{option.id}}">
{{option.name}}
</label>
</div>
</div>
<!-- CHECK BOXES -->
<div ng-if="field.type=='checkbox'" class="form-group" ng-class="{ 'has-error' :
form[field.name].$invalid && form[field.name].$touched,
'has-success': form[field.name].$valid}">
<label class="col-sm-2 control-label">Clouds</label>
<div class="col-sm-6">
<label class="checkbox-inline" ng-repeat="option in field.options">
<input type="checkbox" ng-model="field.data" name="taskGroup" id="{{option.name}}" value="{{option.id}}">
{{option.name}}
</label>
</div>
</div>
</ng-form>
</div>
<br />
<button ng-disabled="myForm.$invalid" type="submit" id="submit">Submit</button>
<br />
</form>
{{entity|json}}
Controller
routerApp.controller('DynamicController1', ['$scope', function ($scope) {
// we would get this from the api
$scope.entity = {
name: "Course",
fields:
[
{ type: "text", name: "firstname", label: "Name", required: true, data: "" },
{ type: "radio", name: "color_id", label: "Colors", options: [{ id: 1, name: "orange" }, { id: 2, name: "pink" }, { id: 3, name: "gray" }, { id: 4, name: "cyan" }], required: true, data: "" },
{ type: "email", name: "emailUser", label: "Email", required: true, data: "" },
{ type: "text", name: "city", label: "City", required: true, data: "" },
{ type: "password", name: "pass", label: "Password", min: 6, max: 20, required: true, data: "" },
{ type: "select", name: "teacher_id", label: "Teacher", options: [{ name: "Mark" }, { name: "Claire" }, { name: "Daniel" }, { name: "Gary" }], required: true, data: "" },
{ type: "checkbox", name: "car_id", label: "Cars", options: [{ id: 1, name: "bmw" }, { id: 2, name: "audi" }, { id: 3, name: "porche" }, { id: 4, name: "jaguar" }], required: true, data: "" }
]
};
$scope.submitForm = function () {
$log.debug($scope.entity);
}
}]);
routerApp.directive("dynamicName",function($compile){
return {
restrict:"A",
terminal:true,
priority:1000,
link:function(scope,element,attrs){
element.attr('name', scope.$eval(attrs.dynamicName));
element.removeAttr("dynamic-name");
$compile(element)(scope);
}
}
})
angularjs
angularjs
edited Jan 1 at 11:19
James Z
11.2k71935
11.2k71935
asked Jan 1 at 6:32
KrishKrish
1,22762156
1,22762156
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can add one more property called value which will be used as the model so you can get the values easily.
{type: "checkbox", name: "car_id", label: "Cars" ,
options:[{id: 1, name: "bmw", value:false},
{id: 2, name: "audi", value:false },{id: 3, name: "porche", value:false},
{id: 4, name: "jaguar", value:false}], required: true, data:""}
And in your model, use this as the model
<input type="checkbox" ng-model="option.value"
name="taskGroup" id="{{option.name}}" value="{{option.id}}">
Demo
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993486%2fhowto-handle-multiple-check-boxes-data-in-angularjs-dynamic-forms%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can add one more property called value which will be used as the model so you can get the values easily.
{type: "checkbox", name: "car_id", label: "Cars" ,
options:[{id: 1, name: "bmw", value:false},
{id: 2, name: "audi", value:false },{id: 3, name: "porche", value:false},
{id: 4, name: "jaguar", value:false}], required: true, data:""}
And in your model, use this as the model
<input type="checkbox" ng-model="option.value"
name="taskGroup" id="{{option.name}}" value="{{option.id}}">
Demo
add a comment |
You can add one more property called value which will be used as the model so you can get the values easily.
{type: "checkbox", name: "car_id", label: "Cars" ,
options:[{id: 1, name: "bmw", value:false},
{id: 2, name: "audi", value:false },{id: 3, name: "porche", value:false},
{id: 4, name: "jaguar", value:false}], required: true, data:""}
And in your model, use this as the model
<input type="checkbox" ng-model="option.value"
name="taskGroup" id="{{option.name}}" value="{{option.id}}">
Demo
add a comment |
You can add one more property called value which will be used as the model so you can get the values easily.
{type: "checkbox", name: "car_id", label: "Cars" ,
options:[{id: 1, name: "bmw", value:false},
{id: 2, name: "audi", value:false },{id: 3, name: "porche", value:false},
{id: 4, name: "jaguar", value:false}], required: true, data:""}
And in your model, use this as the model
<input type="checkbox" ng-model="option.value"
name="taskGroup" id="{{option.name}}" value="{{option.id}}">
Demo
You can add one more property called value which will be used as the model so you can get the values easily.
{type: "checkbox", name: "car_id", label: "Cars" ,
options:[{id: 1, name: "bmw", value:false},
{id: 2, name: "audi", value:false },{id: 3, name: "porche", value:false},
{id: 4, name: "jaguar", value:false}], required: true, data:""}
And in your model, use this as the model
<input type="checkbox" ng-model="option.value"
name="taskGroup" id="{{option.name}}" value="{{option.id}}">
Demo
answered Jan 1 at 6:41
Just codeJust code
10.4k53066
10.4k53066
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993486%2fhowto-handle-multiple-check-boxes-data-in-angularjs-dynamic-forms%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown