spUtil error message not working

cfrazer
Giga Contributor

Hi guys,

I am working with the Service Catalog and I have added a text box for users on the portal to add rejection comments. I want these comments to be mandatory, however, when I try to add the error message for the rejection comments it does not recognize it and the user is able to reject the order without comments. How can I get the error message to pop-up?

Here is my code:

Body HTML template

<textarea ng-model="c.data.comment" style="color: grey; width: 100%; margin-top: .5em;" placeholder="Rejection Comments" class="form-control" rows="5"></textarea>

Client Controller

function ($scope, $window, spUIActionsExecuter, spUtil) {
	var c = this;
c.action = function(state) {

         if ((c.data.comment ==   undefined || c.data.comment ==   '' )&& state == 'rejected')
						{

                            spUtil.addErrorMessage("Rejection comments cannot be empty.");
return false;

         }

         c.data.op = state;

         c.data.state = state;

         c.server.update();


};

Thank you!

1 ACCEPTED SOLUTION

Rahul Jain11
Kilo Guru

Change your  ng-click="c.action('approved')" to ng-click="action('approved')", do same fro reject.

Hope this time it helps !!!

Thanks

 

View solution in original post

7 REPLIES 7

Mike Patel
Tera Sage

try adding timer

 

spUtil.addErrorMessage("Rejection comments cannot be empty.", 1000);

Rahul Jain11
Kilo Guru

Your controller should look like this. Highlighted is the change

 

function ($scope, $window, spUIActionsExecuter, spUtil) {
var c = this;
$scope.action = function(state) {
if ((c.data.comment == undefined || c.data.comment == '' )&& state == 'rejected') {
spUtil.addErrorMessage("Rejection comments cannot be empty.");
return false;
}
c.data.op = state;
c.data.state = state;
c.server.update();
};

 

Thanks

 

I tried this, but it is still not working. I press the 'Reject' button and it cancels the workflow, but it won't make the comments mandatory.

Rahul Jain11
Kilo Guru

I tried same and it worked for me. Could you please share your html as well.

 

Could you please add an alert in the if block to see control is passing if block or not?

Thanks