- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 05:33 AM
Hi All,
I want to create two reference fields which depends on other like user and task. When i select user then in task field only tickets raised by him should be visible.
Also, providing a button "Add Row" if user clicks on this then new two fields will come and same dependency should work for this row also.
I am struggling on assigning field value dynamically to observe and get newvalue that was changed. Please help me to solve this issue.
<tr ng-repeat="rowCounter in table_data track by $index" id="tableRow_{{rowCounter.number}}">
<td ng-repeat="columnObj in rowCounter.fields">
<div class="form-group" ng-class="{'has-success' : columnObj.value != ''}">
<span ng-switch="columnObj.type">
<span ng-switch-when="reference">
<sn-record-picker field="ed_user" table="columnObj.table" display-field="columnObj.displayField" value-field="columnObj.valueField" search-fields="columnObj.searchFields" name="columnObj.name" default-query='' page-size="100" ng-if="columnObj.table == 'sys_user'" id="user" on-change="c.getLaptopDetails(table)"></sn-record-picker>
<sn-record-picker field="columnObj.value" table="columnObj.table" display-field="columnObj.displayField" value-field="columnObj.valueField" search-fields="columnObj.searchFields" name="columnObj.name" default-query="'assigned_to='+user" page-size="100" ng-if="columnObj.table != 'sys_user'"></sn-record-picker>
</span>
<span ng-switch-when="number">
<input type="number" ng-class="{'form-control-success':columnObj.value > 0}" max="{{columnObj.max}}" min="{{columnObj.min}}" class="form-control" ng-model="columnObj.value" />
</span>
<span ng-switch-when="checkbox">
<input type="checkbox" ng-class="{'form-control-success':columnObj.value > 0}" max="{{columnObj.max}}" min="{{columnObj.min}}" class="form-control checkbox" ng-model="columnObj.value" />
</span>
<span ng-switch-default="">
<input type="text" ng-class="{'form-control-success':columnObj.value != ''}" class="form-control" ng-model="columnObj.value" />
</span>
</span>
</div>
</td>
Client Controller:
$scope.ed_user ={
name: 'approver'
}
$scope.$on("field.change", function(evt, parms) {
if (parms.field.name == 'approver'){
alert(parms.newValue);
$scope.user = parms.newValue;
}
});
laurentchicoinechiragbagdaichiragb
lchicoineThanks in advance.
Regards
Swamy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 04:45 PM
Not sure what you mean by a html variable, you mean a html table?
In the demo widget I made you could display it directly using the $scope.columns array.
Here is the updated HTML code for that example:
<div ng-repeat="column in columns">
<sn-record-picker field="column.field" table="'sys_user'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100"></sn-record-picker>
<sn-record-picker field="column.field2" table="'task'" display-field="'number'" value-field="'sys_id'" search-fields="'short_description'" default-query="column.queryField2" page-size="100"></sn-record-picker>
</div>
<button ng-click="addRow()">
Add row
</button>
<table border="1">
<tr>
<th>User</th>
<th>Task</th>
</tr>
<tr ng-repeat="column in columns">
<td>{{column.field.displayValue}}</td>
<td>{{column.field2.displayValue}}</td>
</tr>
</table>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 05:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 05:43 AM
Hi Lars,
Thanks for your reply!!
As in client controller i am setting ed-user name to approver and assigning this to field in sn-record-picker, for first it is working fine.
But, for second row as again i am assigning ed_user to field same value is getiing set and if i clear value in second row then in first row also value is getting cleared.
so, is there any way to set field="somedynamicvalue" like for first row it is ed_user0 and for second row ed_user1 etc.,
Regards
Swamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2017 11:42 AM
Hi Swamy,
Could you paste your whole code so I can play with it (I have an idea but I would need to test and I don't want to build the whole thing).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 01:50 PM
Your widget had a dependency on a modal page and was getting quite complex so I simply did a quick demo widget that you should be able to adapt to your needs:
HTML:
<div ng-repeat="column in columns">
<sn-record-picker field="column.field" table="'sys_user'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100"></sn-record-picker>
<sn-record-picker field="column.field2" table="'task'" display-field="'number'" value-field="'sys_id'" search-fields="'short_description'" default-query="column.queryField2" page-size="100"></sn-record-picker>
</div>
<button ng-click="addRow()">
Add row
</button>
Client controller:
function($scope, spUtil) {
$scope.columns = [];
$scope.addRow = function(){
var column = {
field: {
displayValue: '',
value: '',
name: 'user-' + $scope.columns.length
},
field2: {
displayValue: '',
value: '',
name: 'task-' + $scope.columns.length
},
queryField2: ""
};
$scope.columns.push(column);
};
$scope.$on("field.change", function(evt, parms) {
if(parms.field.name.startsWith('user-')){
var fieldNumber = parms.field.name.split('-')[1];
var fieldValue = parms.field.value;
$scope.columns[fieldNumber].queryField2 = 'assigned_to=' + fieldValue;
}
});
}