Portal - Custom Button Widget - MRV copy row - disable button
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2019 10:14 AM
Hi All,
I've made a widget which is just a button that can be used on a catalog item form using a macro variable. This button will copy the last row added to the variable set above which is a multi row variable set.
I want the button to be disabled (greyed out) until 1 row has been added to the mutli row variable set as it will have nothing to copy.
My widget code is:
HTML:
<div>
<button type="button" class="btn btn-primary btn-block" ng-click="c.copyLastRow()">Copy Last Row
</button>
</div>
Client Script:
function($scope) {
/* widget controller */
var c = this;
c.copyLastRow = function(){
var g_form = $scope.page.g_form;
var mrvs = JSON.parse(g_form.getValue("activation"));
var lastRow = mrvs[mrvs.length-1];
mrvs.push(lastRow);
g_form.setValue("activation", JSON.stringify(mrvs));
}
}
Any help on how I can make the button greyed out and not usable until at least one row has been added to the MRV?
Thanks
Sam
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2019 11:00 AM
Think I may have got this working, although not sure if I've done this in the best way - still learning. Current code is:
HTML:
<div>
<button type="button" ng-disabled ="c.canCopy()" class="btn btn-primary btn-block" style ="width: 110px;" ng-click="c.copyLastRow()">Copy Last Row
</button>
</div>
Client Script:
function($scope) {
/* widget controller */
var c = this;
var g_form = $scope.page.g_form;
c.canCopy = function() {
var isDisabled = true;
var obj = (g_form.getValue('activation').length !=0) ? isDisabled = false: isDisabled = true;
return isDisabled;
}
c.copyLastRow = function(){
var mrvs = JSON.parse(g_form.getValue("activation"));
var lastRow = mrvs[mrvs.length-1];
mrvs.push(lastRow);
g_form.setValue("activation", JSON.stringify(mrvs));
}
}
As can see i have hard coded the value of the MRV in the getValue in both functions. Ideally I would want this to be dynamic so I could re-use the widget with other MRVs. How would be best to achieve this?
Also any pointers on how I can improve the current code- appreciate it is only a simple widget but just trying to get to grips with how it all works
Thanks
Sam