I'm trying to add one button for adding values to ngmodel of kendo's multi select:
<div ng-controller="MyCtrl">
<select id='my' kendo-multi-select k-options="selectOptions" k-ng-model="selectedIds"></select>
<p ng-show="selectedIds.length">Selected: {{ selectedIds }}</p>
<button ng-click="addSelectedId()">Add selected id</button>
<input ng-model="enteredId" />
</div>
Here is controller
function MyCtrl($scope) {
$scope.selectOptions = {
placeholder: "Select products...",
dataTextField: "ProductName",
dataValueField: "ProductID",
autoBind: false,
dataSource: {
type: "odata",
serverFiltering: true,
transport: {
read: {
url: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Products",
}
}
}
};
$scope.selectedIds = [ 4, 7];
$scope.addSelectedId = function() {
$scope.selectedIds.push(parseInt($scope.enteredId));
console.log($scope.selectedIds);
};
}
Plunker is here:
http://plnkr.co/edit/EH0EaMhFsV2JTdwpkqGg?p=preview
When added to selectedIds, nothing gets added to dropdown select placeholder. Any ideas?
You need to add k-rebind="selectedIds" in your html code
HTML:
<div ng-controller="MyCtrl">
<select id='my' kendo-multi-select k-options="selectOptions" k-ng-model="selectedIds" k-rebind="selectedIds"></select>
<p ng-show="selectedIds.length">Selected: {{ selectedIds }}</p>
<button ng-click="addSelectedId()">Add selected id</button>
<input ng-model="enteredId" />
</div>
Please see this updated plunker example
Related
trying to make a dynamically composed form.
Fields and attributes come from server. Angular should get them and generate a form.
I decided to use directive and runtime compilation.
Mostly all works except a few things.
The problem: $valid is undefined for compiled fields.
For static fields is works.
Please give me an advice.
app = angular.module('dyno', []);
app.controller("fieldCompilation", function($scope) {
$scope.list = [{
id: "0",
name: "A"
},
{
id: "1",
name: "B"
},
{
id: "2",
name: "C"
},
];
});
app.directive("otcDynamic", function($compile) {
return {
link: function(scope, element) {
// Add Text Input with pattern validation and required attr
var template = "<input type='text' name='input3' ng-model='input3' placeholder='input3 [0-9]{2} required' pattern='[0-9]{2}' required='true'/>";
var linkFn = $compile(template);
var content = linkFn(scope);
angular.element(document.getElementById("f3")).append(content);
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.2/angular.min.js"></script>
<div ng-app="dyno">
<div ng-controller="fieldCompilation">
<br><b> Static Input:</b>
<ng-form name="form1">
<div id="f1">
1. Input <input type='text' name='input1' ng-model='input1' placeholder='input1 [0-9]{2} required' pattern='[0-9]{2}' required='true' /><br>
</div>
<br><b> Dynamic Inputs:</b>
<div otc-dynamic>
<div id="f3">
3. Input
</div>
</div>
<br> <b>Details</b>
<div>
Counter: {{ message }}
</div>
<div>
Model Input1: {{ input1 }}
</div>
<div>
Model input3: {{ input3 }}
</div>
<div>
Validation input1: {{ form1.input1.$valid }}<br> Validation input3: {{ form1.input3.$valid }}<br> Validation form1: {{ form1.$valid }}<br>
</div>
</ng-form>
</div>
</div>
Fiddle
I'm trying to get the radio value button value from ng-dialog but it always got undefined.
Here is the dialog template:
<script type="text/ng-template" id="flag-reasons.html">
<div style="padding:10px;">
<span>
What's wrong ?
</span>
<div class="form-group" ng-repeat="flagreason in flagreasons">
<input type="radio" ng-model="fr" name="frname" value="{{flagreason.id}}"> {{flagreason.title}}
</div>
<div class="form-group">
<button type="button" ng-click="validFlag()">
Valider
</button>
</div>
</div>
</script>
Here is the partial js where I start with the dialog:
$scope.openFlag = function(){
$scope.dialog = ngDialog.open({ template: 'flag-reasons.html',
className: 'ngdialog-theme-default', scope: $scope });
$scope.validFlag = function(){
console.log($scope.fr);
}
}
I have tried ng-value as below:
<input type="radio" ng-model="fr" name="frname" ng-value="flagreason.id"> {{flagreason.title}}
but it still got undefined
Notice that it works when I directly set the value of the radio button like:
<input type="radio" ng-model="fr" name="frname" value="5"> {{flagreason.title}}
The issue is with ngmodel that's not getting update. You have to initialise ngmodel first in the template.
flag-reasons.html
<script type="text/ng-template" id="flag-reasons.html">
<div style="padding:10px;">
<span>
What's wrong ?
</span>
<div class="form-group" ng-repeat="flagreason in flagreasons">
<input type="radio" ng-model="cb.fr" name="frname" value="{{flagreason.id}}">{{flagreason.id}} - {{flagreason.title}}
</div>
<div class="form-group">
<button type="button" ng-click="validFlag()">
Valider
</button>
</div>
</div>
</script>
Controller
angular.module("app", ['ngDialog'])
.controller('Ctrl',function ($scope, ngDialog) {
'use strict';
$scope.cb = {};
$scope.flagreasons = [
{id: 1, title: 'title1'},
{id: 2, title: 'title2'},
{id: 3, title: 'title3'}
];
$scope.openFlag = function(){
$scope.dialog = ngDialog.open({ template: 'flag-reasons.html',
className: 'ngdialog-theme-default', scope: $scope });
$scope.validFlag = function(){
console.log($scope.fr);
}
}
$scope.$watch('cb.fr', function (v) {
console.log(v);
});
});
Working Fiddle: JSFiddle
<div data-ng-controller="OfficeController" class="container">
<div class="row col-md-12" style="margin:10px;">
<form name="Office">
<div class="col-sm-12">
<label for="Name" class="form-group col-sm-2 control-label">Name</label>
<div class="col-sm-4">
<input type="text" class="form-group col-xs-6" id="Name" placeholder="Name" ng-model="Name" required />
</div>
<label for="Org_ID" class="form-group col-sm-2 control-label">Org_ID</label>
<div class="col-sm-4">
<input type="text" class="form-group col-xs-6" id="Org_ID" placeholder="Org_ID" ng-model="Org_ID" required />
</div>
</div>
</form>
</div>
</div>
i have two textboxes in view
adding button to uigrid column for get row data and call get
$scope.gridOptions = {
data: 'Offices',
columnDefs: [
{ field: 'OFFICE_ID', displayName: 'OFFICE_ID' },
{ field: 'Name', displayName: 'Name' },
{ field: 'Org_ID', displayName: 'Org_ID' },
{
name: 'ShowScope',
cellTemplate: '<button class="btn primary" ng-click="grid.appScope.get(row)">Click Me</button>'
}
],
filterOptions: { filterText: '', useExternalFilter: false },
showFilter: true,
enableFiltering: true,
showGridFooter: true,
};
alert(res.Name) shows me correct name but i am unable to set textbox name value??
$scope.get = function (row) {
alert(row.entity.OFFICE_ID);
var promiseGetSingle = OfficeService.get(row.entity.OFFICE_ID);
promiseGetSingle.then(function (pl) {
var res = pl.data;
alert(res.Name);
$scope.OFFICE_ID = res.OFFICE_ID;
$scope.Org_ID = res.Org_ID;
$scope.Name = res.Name;
$scope.IsNewRecord = 0;
},
function (errorPl) {
console.log('failure loading Organization', errorPl);
});
}
Any idea how to set textbox value through scope,ir any method, what i want is when users click on row button i want to poulate fields by getting data from that particular row...in UI Grid Angularjs
Please try as shown below.
$scope.Name='';//define the variable globally
$scope.get = function (row) {
var promiseGetSingle = OfficeService.get(row.entity.OFFICE_ID);
promiseGetSingle.then(function (pl) {
$scope.Name = res.Name;
},
}
I am using kendo-ui with AngularJS. I have a parent grid and on the expansion of the row I have to show two sub grids, for that I don't want to call server separately. I have developed a service which returns data of both grids, now I want to bind the data to the grid. How to do that? Here is the code:
$scope.mainGridOptions = {
columns: [
{ field: "id", title:"ID",width: "50px" },
{ field: "name", title:"Name", width:"200px" },
],
dataSource: {
transport: {
read: function (e) {
var params = {};
var dataObj = ServerAPIs.getStudents(params, function(){
e.success(dataObj.result);
},function(){
alert('something went wrong');
});
}
},
pageSize: 20,
},
sortable: true,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
filterable: true,
reorderable: true,
resizable: true,
detailInit: function(e) {
(function(e){
var params = {
"student-id" : e.data.id
};
var dataObj = ServerAPIs.getStudentDetails(params, function(data){
if(data.result.dataset1.length > 0){
//what to do here? how to access child grid1?
}
if(data.result.dataset2.length > 0){
//what to do here? how to access child grid2?
}
},function(){
alert('something went wrong');
});
})(e);
}
};
Here is the html:
<kendo-grid id='maingrid' options="mainGridOptions">
<div k-detail-template >
<div class='grid_loader'>
<br/>
<span class="spinner_forms"> </span>
<br/>
</div>
<div class='details' style='display:none'>
<div class="center-block" style="width: 800px;" kendo-grid k-options="grid1Options(dataItem)"></div>
<br />
<div class="center-block" style="width: 800px;" kendo-grid k-options="grid2Options(dataItem)"></div>
</div>
</div>
In Javascript, I selected child element using find method and initiated the grid.
detailInit: function(e) {
(function(e){
var params = {
"student-id" : e.data.id
};
var dataObj = ServerAPIs.getStudentDetails(params, function(data){
if(data.result.dataset1.length > 0){
e.detailRow.find(".child-grid-1").kendoGrid({
dataSource: {
data: data.result.dataset1,
},
columns: [//your columns here],
//other grid options
});
}
if(data.result.dataset2.length > 0){
e.detailRow.find(".child-grid-2").kendoGrid({
dataSource: {
data: data.result.dataset2,
},
columns: [//your columns here],
//other grid options
});
}
},function(){
alert('something went wrong');
});
})(e);
}
In html page, following modification needs to be made:
<kendo-grid id='maingrid' options="mainGridOptions">
<div k-detail-template >
<div class='grid_loader'>
<br/>
<span class="spinner_forms"> </span>
<br/>
</div>
<div class='details' style='display:none'>
<div class="child-grid-1" style="width: 800px;"></div>
<br />
<div class="child-grid-2" style="width: 800px;"></div>
</div>
</div>
I have a variable set to true in ng-click but the div underneath is not displaying. I've followed this post but it looks like it doesnt work in maybe ng-repeat? Here's the plunker: http://plnkr.co/edit/90G1KAx9Fmf2SgRs5gYK?p=preview
angular.module('myAppApp', [])
.controller('MainCtrl', function ($scope) {
$scope.notes = [{
id: 1,
label: 'First Note',
done: false,
someRandom: 31431
}, {
id: 2,
label: 'Second Note',
done: false
}, {
id: 3,
label: 'Finished Third Note',
done: true
}];
$scope.reach= function (id) {
//the assignment below works
//$scope.flag = true;
alert("hello there");
};
});
<div ng-app="myAppApp">
<div ng-controller="MainCtrl">
<div ng-repeat="note in notes">
{{note.id}} - {{note.label}} -
click me
</div>
<div class="row" id="" ng-show="flag">I'm Here</div>
</div>
</div>
It should be ng-click="$parent.flag = true;reach(111);"
click me
Outside ng-repeat
You question is unclear, you could use ng-repeat inside ng-repeat, by maintaining variable in ng-repeat parent scope. and access parent scope using $parent. annotation inside ng-repeat
<div ng-repeat="note in notes">
{{note.id}} - {{note.label}} -
click me
<div class="row" id="" ng-show="$parent.selected == note.id">I'm Here</div>
</div>
</div>
Inside ng-repeat
I would advise you to use ng-init
<div ng-repeat="note in notes" ng-init="parent=$parent">
and after that
click me
Please see demo below
angular.module('myAppApp', [])
.controller('MainCtrl', function($scope) {
$scope.notes = [{
id: 1,
label: 'First Note',
done: false,
someRandom: 31431
}, {
id: 2,
label: 'Second Note',
done: false
}, {
id: 3,
label: 'Finished Third Note',
done: true
}];
$scope.reach = function(id) {
//$scope.flag = true;
alert("hello there");
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body>
<div ng-app="myAppApp">
<div ng-controller="MainCtrl">
<div ng-repeat="note in notes" ng-init="parent=$parent">
{{note.id}} - {{note.label}} -
click me
</div>
<div class="row" id="" ng-show="flag">I'm Here</div>
</div>
</div>
</body>