Service Portal Widget Mandatory Field

Richard Ounswor
Kilo Contributor

Morning all, hopefully just a nice simple one for all those experts out there. Being new to scripting I have no idea how to complete this. I have created a custom widget that shows a number of fields which logs a request on your service desk. However there are two fields that i simply want to make mandatory and show in red if they are not filled in when the submit button is pressed or something similar, whatever is easiest. The existing code is as below, the fields to be mandatory are the Reason for nomination and value examples controls towards the bottom of the HTML template

HTML:

find_real_file.png

CS:

find_real_file.png

Server:

find_real_file.png

 

Any advice on the quickest simplest way to do this would be greatly appreciated

 

 

 

 

 

1 ACCEPTED SOLUTION

Bhagya Lakshmi
Mega Guru

Hi,

Here, I just give you one example. I hope this may help.

 

In HTML:-

 

<label style="color:red">{{m1}}</label><label>You text1</label>

<label style="color:red">{{m2}}</label><label>You text2</label>

<button ng-click="c.addItem()">Save</button>

 

In Client script:

c.addItem = function()
{
if(!model1 && !model2)
{
$scope.m1 = "*";
$scope.m2 = "*";

}
else if(!model1)
{
$scope.m1 = "*";
}
else if(!model2)
{
$scope.m2 = "*";
}
else
{
/*your code*/
}
 

}

 

Note: You will use your ng-model variable names in place of model1 and model2.

 

 

 

 

View solution in original post

4 REPLIES 4

Bhagya Lakshmi
Mega Guru

Hi,

Here, I just give you one example. I hope this may help.

 

In HTML:-

 

<label style="color:red">{{m1}}</label><label>You text1</label>

<label style="color:red">{{m2}}</label><label>You text2</label>

<button ng-click="c.addItem()">Save</button>

 

In Client script:

c.addItem = function()
{
if(!model1 && !model2)
{
$scope.m1 = "*";
$scope.m2 = "*";

}
else if(!model1)
{
$scope.m1 = "*";
}
else if(!model2)
{
$scope.m2 = "*";
}
else
{
/*your code*/
}
 

}

 

Note: You will use your ng-model variable names in place of model1 and model2.

 

 

 

 

Hi there, many thanks for the reply but I seem to be missing something. I'm newbie to this so have now idea where to look.

I have the below in HTML

 

<div class="form-group">

<label style="color:red">{{m1}}</label><label>Reason for nomination (Please be as detailed as possible to help us in the selection process)</label>
<input class="form-control" name="value" ng-model="c.data.u_nomination_reason" required>

</div>

<div class="form-group">
<label style="color:red">{{m2}}</label><label>Give some examples where you think the nominee has 'lived' the values.</label>
<input id="value" name="value2" class="form-control"required minlength="10" ng-model="c.data.u_value_examples" >
</div>

 

and the below in my client script:

find_real_file.png

 

For some reason now the two boxes referenced to do display red and my submit button does nothing am I using the wrong name or is the code incorrect in some way?

Thanks Bhagya Lakshmi,

The code snippet was quite helpful.

Richard Ounswor
Kilo Contributor

Ignore the last post I now have it working through a bit of trial and error, many thanks for your help