how to make this submit button to act like a enter button when pressed ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 04:41 PM
how to make this submit button to act like a enter button when pressed ?
<input
autofocus="autofocus"
class="input custom-input-height barcode-input"
ng-model="barCode"
placeholder="Please tap here before scanning barcode..."
type="text"
required
id="barcodeInput"
ng-keypress="handleKeyPress($event, 'barcode')">
<button
class="btn btn-primary checkin"
ng-click="handleCheckIn()"
ng-disabled="!barCode || runningRequests > 0"
type="submit">
Check-In
</button>
</div>
</form>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 07:33 PM
try this
<input
autofocus="autofocus"
class="input custom-input-height barcode-input"
ng-model="barCode"
placeholder="Please tap here before scanning barcode..."
type="text"
required
id="barcodeInput"
ng-keypress="handleKeyPress($event, 'barcode')"
onkeypress="if(event.keyCode == 13) document.getElementById('checkInButton').click();">
<button
class="btn btn-primary checkin"
ng-click="handleCheckIn()"
ng-disabled="!barCode || runningRequests > 0"
type="submit"
id="checkInButton">
Check-In
</button>
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 07:49 PM
@Ankur Bawiskar when i click on the onscreen keyboard it works but when i press on the check in button , it is not sending as enter button . what i was trying to archive is that the autofocus is not working on my widget.
when i use the external barcode reader and the onscreen keyboard it will cursor will stay at the barcode text box but not when i press on the check in button
here is the code for the check in :
// Comprehensive Focus Management
function setInitialFocus(inputId = 'barcodeInput') {
$timeout(function () {
var barcodeInput = document.getElementById(inputId); // Get the input element
if (barcodeInput) {
barcodeInput.focus(); // Focus the input field
barcodeInput.click(); // Trigger a click (important for iOS virtual keyboard)
// Ensure focus reliability (especially on iOS)
setTimeout(function () {
barcodeInput.focus(); // Reapply focus
barcodeInput.setSelectionRange(barcodeInput.value.length, barcodeInput.value.length); // Set cursor at the end
}, 50); // Slight delay for stability
}
}, 0); // Execute focus logic immediately
}