Service Portal Widget Set Focus

adam_katulak
Tera Contributor

Hi,

Does anyone know of a way to set the focus of an input in a Service Portal Widget?

I have an input, that onChange calls a script in the client controller.   As part of the client controller script, I need to automatically set focus on another input field at the bottom of my form.

Here are some snippets

HTML

<div class="form-group required" ng-if="c.data.scan_location_barcode=='yes'">

          <label class="control-label">${Location barcode}</label>

          <input class="form-control" ng-model="c.data.location_barcode" field="location_barcode" ng-change="c.setLocation()" required="true" ng-model-options="{debounce: 500}") />

          <div ng-if="c.isNative">${Scan using your phone}<i class="fa fa-barcode fa-4" ng-click="c.getLocationBarcode()"></i></div>

</div>

<div ng-if="!c.manualScan">

        <input class="form-control" id="barcode" type="text" ng-model="c.data.barcode" ng-model-options="{debounce: 50}" ng-change="c.display()" ng-disabled="c.data.isLoading"/>

</div>




Client Controller

c.setLocation = function() {

c.server.update().then(function(data) {

c.data.customer = data.customer;

c.data.room = data.room;

c.data.location = data.location;

//Adding field values and listeners

$scope.company = {

displayValue : c.data.customer,

value : c.data.customer_id,

name : 'company'

};

$scope.department = {

displayValue : c.data.location,

value : c.data.location_id,

name : 'department'

};

$scope.room = {

displayValue : c.data.room,

value : c.data.room_id,

name : 'room'

};

$window.setTimeout(1000);

var el = $window.document.getElementById("barcode");

el.focus();

});

1 ACCEPTED SOLUTION

Domenic Horner
Tera Expert

Hey Adam,



You should be able to append "autofocus" into your input field.


HTML input autofocus Attribute



<input class="form-control" id="barcode" type="text" ng-model="c.data.barcode" ng-model-options="{debounce: 50}" ng-change="c.display()" ng-disabled="c.data.isLoading" autofocus/>  



Let me know if this works for you.



- Dom


View solution in original post

6 REPLIES 6

I have unfortunately not found an answer for this. I know that the London release will have a lot more available for the accessibility portion of ServiceNow so I am hoping that upgrading will solve this issue.

Try this in the Client Controller that contains the search bar:

$window.document.getElementById("searchBarId").focus();