I'm making a dynamic registration form My dynamic form example. The data written in those inputs will be later sent to some API.
<div ng-repeat="item in CustomRegistrationForm"
class="form-group text-field-para" style="margin: 10px">
<input type="{{item.Type}}" id="{{'A'+$index}}"
class="form-control" name="{{TmpName}}"
ng-model="RegistationSubscriberData.User.CustomRegistrationForm[$index].Name">
</div>
CustomRegistration is a JSON made like this: https://jsoneditoronline.org/?id=5396efadcf9d475a9fee6e558e8b807c .
By my logic ng-models would have to be set (in my case) as: "FirstName", "Email", "GSMnumber",... But it just saves as the last string in the ng-model, in my case "Name". I tried to use item.Name also but it didn't make any difference. Also if I tried to "console.log(CustomRegistration[0].Name)" it worked perfectly and output "FirstName"
Can someone explain to me why in this case my 'type' works perfectly (Dynamicly) but ng-model can't work with dynamic variable. This is my first question here so if I made any mistakes I apologise in advance.
You have to create array for the ng-model then you can add dynamically into that array as below.
<div ng-app ng-controller="TestController">
<div ng-repeat="item in CustomRegistrationForm" class="form-group text-field-para" style="margin: 10px">
<input type="{{item.Type}}" id="{{'A'+$index}}"
class="form-control" name="{{TmpName}}"
ng-model="Users[item.Name]">
</div>
<p> {{Users}} </p>
</div>
In Controller
function TesyController($scope) {
$scope.RegistationSubscriberData = {};
$scope.CustomRegistrationForm = [
{
"Label": "First name",
"Name": "FirstName",
"Type": "text",
"Mandatory": true,
"Length": 20,
"showPlaceHolder": false,
"Regex": "/^[a-z ,.'-]+$/i",
"Validator": "",
"requireRetypePassword": false,
"strengthValidatorEnabled": false,
"strengthComplexityLevel": false,
"Format": ""
},
{
"Label": "Email",
"Name": "Email",
"Type": "email",
"Mandatory": true,
"Length": "",
"showPlaceHolder": false,
"Regex": "",
"Validator": false,
"requireRetypePassword": false,
"strengthValidatorEnabled": false,
"strengthComplexityLevel": false,
"Format": ""
},
{
"Label": "Phone number (international format)",
"Name": "GSMNumber",
"Type": "text",
"Mandatory": false,
"Length": "",
"showPlaceHolder": false,
"Regex": "/^[a-z ,.'-]+$/i",
"Validator": "",
"requireRetypePassword": false,
"strengthValidatorEnabled": false,
"strengthComplexityLevel": false,
"Format": ""
},
{
"Label": "Password",
"Name": "password",
"Type": "password",
"Mandatory": true,
"Length": "",
"showPlaceHolder": false,
"Regex": "",
"Validator": false,
"requireRetypePassword": true,
"strengthValidatorEnabled": true,
"strengthComplexityLevel": false,
"Format": ""
}
]
}
For reference you can refer below fiddle links
fiddle
fiddle 2
Hope this will help you.
Related
I have a rudimentary understanding of AngularJS and have a couple (possibly stupid) questions about ng-if and ng-repeat.
If I have a ng-repeat that looks like this:
For all containers without titles, would the ng-repeat produce those containers and not show them? Or do they simply don't exist? The reason I ask is I've tried to replace ng-if with ng-show, but it does not produce the same outcome of "hiding" containers that do not have titles.
Is there a way to code a ng-if to say if the next container has no title, then do something. I tried something like ng-if="item.title=='' && $index+1", without any luck.
Any suggestions?
My data looks like this:
"_sections": [{
"_bootstrap_cells": 6,
"_count": 2,
"visible": true,
"columns": [{
"fields": [{
"name": "type_of_account",
"type": "field"
}, {
"name": "routing_transit_number",
"type": "field"
}]
}, {
"fields": [{
"name": "type_of_payment",
"type": "field"
}, {
"name": "check_digit",
"type": "field"
}]
}],
"caption": "Direct Deposit",
"id": "b456b9d2137ac340177c36328144b0ef"
}, {
"_bootstrap_cells": 12,
"_count": 1,
"visible": true,
"columns": [{
"fields": [{
"name": "account_number",
"type": "field"
}, {
"name": "account_title",
"type": "field"
}, {
"name": "financial_institution_name",
"type": "field"
}]
}],
"caption": "",
"id": ""
}
}]
The first section has two columns and a bootstrap cell value of 6 for each column, the second section only has one column and a bootstrap cell of 12. Since the second doesn't have a caption, I want it to be appended to the first section, but keep both sections' bootstrap formatting.
If containers is an array then it does not have a title property. You need to check the title on each item.
Also note that ng-if will not hide the content, but remove it or not insert it into the DOM. The counterpart of ng-show is ng-hide.
angular.module('appModule', [])
.controller('MyController', [function() {
this.containers = [{
aaa: 1,
title: 'One'
}, {
aaa: 2,
title: ''
}, {
aaa: 3,
title: 'Three'
}]
}]);
angular.bootstrap(window.document, ['appModule'], {
strictDi: true
});
<div ng-controller="MyController as myCtrl">
<div ng-repeat="item in myCtrl.containers track by $index">
<div ng-if="item.title!=''">{{$index}}. {{item.title}}</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.7/angular.min.js"></script>
I have Json request as below. I need to filter only values from key with intrsted in table.I am new to filters and handling key in angular. I attached my JSON request and response, need assistane.
JSON:
var customer =
[
[
{
"businessuserid": 44,
"businessusername": "rk business New",
"businessusermobile": "00",
"businessusercountrycode": "91",
"admin": true,
"mobilevalidated": false,
"emailvalidated": false,
"email": "riteshnew#gmail.com",
"upin": "000044"
}
],
[
{
"approved": true,
"businessuserid": 43,
"businessusername": "Cakey Bakes",
"businessusermobile": "8050663763",
"businessusercountrycode": "91",
"admin": true,
"mobilevalidated": true,
"emailvalidated": false,
"email": "preethi#groupz.com",
"upin": "000043"
}
],
[
{
"intrsted": true,
"attended": false,
"businessuserid": 44,
"businessusername": "rk business New",
"businessusermobile": "00",
"businessusercountrycode": "91",
"admin": true,
"mobilevalidated": false,
"emailvalidated": false,
"email": "riteshnew#gmail.com",
"upin": "000044"
}
],
[
{
"intrsted": true,
"attended": false,
"businessuserid": 52,
"businessusername": "Cars workshop",
"businessusermobile": "9535000636",
"businessusercountrycode": "91",
"admin": true,
"mobilevalidated": true,
"emailvalidated": false,
"email": "preethi#car.com",
"upin": "000052"
}
]
Html:
<table ng-repeat="item in customers | filter: { intrsted: true }">
<td>{{item.businessusername}}</td>
<tr>
</table>
There is nothing wrong with your filter usage. Problem is at your ng-repeat usage. If you double check your json object you will see your every item is another array so you need to use inner object as array. Fix your html like this
<table ng-repeat="item in customers | filter: { intrsted: true }">
<td>{{item[0].businessusername}}</td>
</table>
You see your item is just an another array so use it like item[0] and you will get the result you want...
UPDATE
for showing inner array list on html use second ng-repeat inside of first ng-repeat...
<table ng-repeat="item in customers | filter: { intrsted: true }">
<td ng-repeat="customer in item">{{customer.businessusername}}</td>
</table>
I have this sample json data:
{
"sessionsData" :[{
"isActive": true,
"isInactive": false,
"isScheduled": false,
"isExpired": false,
"candidateName":"Payal Singh",
"email": "ggera#sapient.com"
},
{
"isActive": false,
"isInactive": true,
"isScheduled": false,
"isExpired": false,
"candidateName":"Shyam Singh",
"email": "ggera#sapient.com"
},
{
"isActive": false,
"isInactive": false,
"isScheduled": true,
"isExpired": false,
"candidateName":"Payal Singh",
"email": "ggera#sapient.com"
},
{
"isActive": false,
"isInactive": false,
"isScheduled": false,
"isExpired": true,
"candidateName":"Payal Singh",
"email": "ggera#sapient.com"
}]
}
Now I want to count only the entries which have "isActive" property set to true by using angular.
Anyone have any suggestions?
arr.sessionsData.filter(function(obj,key){
return obj.isActive==true
})
OR:
ECMA6 :
var arrFiltered = arr.sessionsData.filter((obj,key)=>
obj.isActive==true
)
https://docs.angularjs.org/api/ng/filter/filter. Follow this link, it is very detailed.I went around it like this:
$scope.activeEntries = $filter('filter')($scope.session.sessionsData, {isActive: true});
where $scope.session.sessionsData is the array in which I retrieved the json data.
I am starting with an array of sources
$scope.sources = [
{
"type": "register",
"name": "Register 1",
"balance": 100
},
{
"type": "register",
"name": "Register 2",
"balance": 100
},
{
"type": "register",
"name": "Register 3",
"balance": 200
},
{
"type": "office",
"name": "Change Drawer",
"balance": 200
},
{
"type": "office",
"name": "Safe",
"balance": 500
}
];
I'm successfully loading the options
<div class="form-group">
<label>Transfer <strong>{{amount(count, start, selectedItem.balance) | currency}}</strong> To:</label>
<select id="transferTo" class="form-control" ng-model="form.to" ng-options="item.name for item in sources | filter:{type:'office'}">
<option value="">-- Select a Source --</option>
</select>
</div>
I've tried using a $timeout function to select it after it works, but it doesn't pass back the correct value to my function
$timeout(function () {
$('#transferTo').val('1');
}, 200);
How would I set the "Safe" as the default option selected when the form loads?
You will need to set a value on your scope that you're setting ng-model equal to:
$scope.form.to = $scope.sources[4];
If your list (sources) is dynamic you can filter the array like this, which will return an array (but leave your array untouched).
filterFilter($scope.sources, {name: 'Safe'})
fiddle
All the question is in my title =).
I started with checkBox Tree exemple, add property checked:false for the first level that work i see my checkbox just on left icone folder.
But have radio in level that is so different, i tryed some change to transform checkbox in radio, but nothing *:_:*
Some topic given by broogle talk only some levels with checkbox but none with radio.
Have you an idea ?
Thx a lot, have a nice day.
The Example is using a JSON file to load the nodes.
In de JSON file you can set "checked" to true or false.
{"text": "Grocery List",
"cls": "folder",
"children": [{
"text": "Bananas",
"leaf": true,
"checked": false
},{
"text": "Milk",
"leaf": true,
"checked": false
},{
"text": "Cereal",
"leaf": true,
"checked": false
},{
"text": "Energy foods",
"cls": "folder",
"children": [{
"text": "Coffee",
"leaf": true,
"checked": false
},{
"text": "Red Bull",
"leaf": true,
"checked": false
}]
}]}
You can only have a checkbox in the tree but you can always write your own extension :)
Well, i'm brb on this thread for give a little function. put that on your tree and normaly you have checkbox with radio behavior.
listeners: {
'checkchange': function( n, check )
{
if( check )
{
var p = n.parentNode;
p.eachChild( function( c )
{
if( c.isLeaf() && c.get('checked') )
{
c.set('checked', false);
}
});
n.set('checked', true);
}
else
{
n.set('checked', false);
}
}
}