- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2017 01:37 PM
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();
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2017 07:29 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2018 01:47 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 4 weeks ago
Try this in the Client Controller that contains the search bar:
$window.document.getElementById("searchBarId").focus();