I want the select and checkbox button to be selected depending on the given JSON format.
{
"autoselect": [
"doloremque",
"amet natus aut",
"tenetur"
],
"component": "checkbox",
"description": "blanditiis exercitation quidem molestiae eius aliquam deserunt consequat",
"editable": false,
"label": "vel qui autem",
"options": [
"mollitia voluptatum",
"doloremque",
"amet natus aut",
"inventore",
"tenetur"
],
"required": true
},
{
"autoselect": [
"debitis exercitationem"
],
"component": "select",
"description": "nihil animi ut qui consequuntur velit",
"editable": false,
"label": "dolorum quo",
"options": [
"aliquid",
"eius",
"voluptatem aliqua vel",
"earum voluptatem",
"debitis exercitationem"
],
"required": true
},
{
"autoselect": [
"doloremque",
"amet natus aut",
"tenetur"
],
"component": "checkbox",
"description": "blanditiis exercitation quidem molestiae eius aliquam deserunt consequat",
"editable": false,
"label": "vel qui autem",
"options": [
"mollitia voluptatum",
"doloremque",
"amet natus aut",
"inventore",
"tenetur"
],
"required": true
}
Both select and checkbox button should display on the basis of number of element in options array. And the value of radio button based on autoselect value. If autoselect value match with any value of options then corresponding option select and checkbox button will be true and remaining will false.
And if JSON object does not contain autoselect value then none of the select and checkbox button should be selected initially.
Contoller.js
var app = angular.module('myApp',[]);
app.controller('MainCtrl', function ($scope, $http, $log) {
$scope.selected = [];
$http({
method: 'GET',
url: 'data.json'})
.then(function(response) {
$scope.error = response;
$scope.renderTags = response.data.data;
$log.info(response);
}, function(reason){
$scope.error = reason.data;
});
$scope.clicked=function(option){
console.log(option);
}
});
HTML code
<div class="mainBody" ng-repeat="tag in renderTags.form_fields track by $index">
<div ng-switch on="tag.component">
<div ng-switch-when="checkbox">
: </br>
<div ng-repeat="select in tag.options" ng-disabled="!tag.editable" ng-required="tag.required">
<span ng-if="tag.autoselect!== null">
<span ng-if="tag.autoselect[0] === select">
<input type="checkbox" checked ng-value="select" name="$index" ng-click="clicked(select)"/>
</span>
<span ng-if="tag.autoselect[0] !== select">
<input name="$index" type="checkbox" ng-value="select">
</span>
</span>
</div>
</div></br>
<div ng-switch-when="select">
:
<select ng-disabled="!tag.editable" ng-required="tag.required" ng-selected="selection">
<option ng-repeat="choice in tag.options"></option>
</select>
</div></br>
<div ng-switch-default>
</div>
</div>
</div>
when autoselect values is not there that time my code is not working.
Kindly help me in particular scenario.
Thanks in advance..
Aucun commentaire:
Enregistrer un commentaire