Need help with script to build a select box type variable on a custom Service Portal form

patricklatella
Mega Sage

Hi all,

I'm building a custom widget to present a custom form in Service Portal, and need to build a Select Box type variable...and I'm struggling with the script in the HTML field of the widget.  Here's where I'm at so far, I got this from Stackoverflow.com and am trying to manipulate for my need.  Anyone done this before?  Thanks!

<div class="select">
         <select [(ngModel)]="corporationObj" class="form-control col-lg-8" #corporation required>
             <option *ngFor="let corporation of corporations"></option>    
         </select>
         
     </div>
1 ACCEPTED SOLUTION

 <div class="form-group">
 <label for="technology">What technology is this related to?</label>
 <select id="technology" name="technology"
 ng-model="c.data.technology" class="form-control">
 <option value="">--None--</option>-->
 <option value="1">Help Desk</option>
 <option value="2">IT</option>
 <option value="3">Payroll</option>
 </select>
 </div>

View solution in original post

22 REPLIES 22

patricklatella
Mega Sage

here's my latest...this is working but it's showing the first option by default...need to have it be empty at first like a real Select Box variable...anyone see what I'm missing?  I also need the variable to be mandatory.

<div class="form-group">
<label for="technology">What technology is this related to?</label>
<select id="technology" name="technology"
[(ngModel)]="technology" class="form-control">
<option value="1">Help Desk</option>
<option value="2">IT</option>
<option value="3">Payroll</option>
</select>
</div>

 

 

patricklatella
Mega Sage

here's my latest...after remembering that a select box with "Include none" checked on the variable record will show "None" on load...so my script below is good.  I just need to make the field mandatory, which would also mean it needs to not accept "None" as a choice.  it's getting there though!  

<div class="form-group">
<label for="technology">What technology is this related to?</label>
<select id="technology" name="technology"
[(ngModel)]="technology" class="form-control">

<option value="0">None</option>
<option value="1">Help Desk</option>
<option value="2">IT</option>
<option value="3">Payroll</option>
</select>
</div>

Try below code,

<div class="form-group">
 <label for="technology">What technology is this related to?</label>
 <select id="technology" name="technology"
 ngModel="technology" class="form-control" required>


<option value="0">None</option>
 <option value="1">Help Desk</option>
 <option value="2">IT</option>
 <option value="3">Payroll</option>
 </select>
 </div>

 

Hi Shweta, thanks for your response.

I tried your code...it is not making the field mandatory unfortunately, and I'm trying to verify if the data object for "technology" is passing back to the client script.  here's my client script...the log to the console shows "undefined".  Any thoughts on what's wrong?

 

function($scope) {

var c = this;


c.addItem = function(){
var tech = c.data.technology;
console.log('technology is '+tech);
c.server.update().then(function(response){
c.data = {};
})

}
}