"Implementing the textbox.blur function in AngularJS to trigger after hitting the enter

My AngularJS app is designed for iPads using the Safari browser. I have a text box at the top that serves as a filter for an ng-repeat. I want to close the keyboard on the iPad when someone clicks the 'GO' button. I found a solution to hide the keyboard by blurring the input element here

I am utilizing the AngularUI library and triggering the onKeyUp event to detect the enter key.

This is the HTML for the textbox. I'm using the ui-keypress event to call the keypressCallback function:

<input ng-model="query" type="text" id="query" placeholder="product name or number" class="big radius" autocomplete="off" ui-keypress="{13:'keypressCallback($event)'}">

Below is a simplified version of the JavaScript code containing only the keypressCallback function:

var MyApp = angular.module( "MyApp", ['ui'] );

MyApp.controller(
'SwatchListCtrl',
function ($scope, $http) {      

    $scope.keypressCallback = function($event) {
        alert('enter');
        $event.preventDefault();
    };      

}
);

I have attempted to set focus to the document and body to blur the textbox, but it has been unsuccessful.

You can view the development version of my project at the following URL:

Thank you in advance, Gav

Answer №1

Instead of using input.blur(), have you considered using a different approach? Here's an alternative solution:

$scope.keypressCallback = function($event) {
    $event.target.blur();
};

Try this out, it should do the trick.

Answer №2

Quick fix:

document.getElementById('inputId').blur();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript: Determining the point on a perpendicular line that is consistently a fixed distance away

I am currently working on finding a point that is equidistant from the midpoint of a perpendicular line. This point will be used to create a Bézier curve using the starting and ending points, along with this intermediate point. After calculating the perp ...

Experiencing issues calling a function in Vue.js while working with the SDK JavaScript?

When attempting to integrate the JavaScript SDK into Vuejs by utilizing a Facebook login button, I encountered an issue: <template> <div> <div class="fb-login-button" data-max-rows="1" data-size="large" data-button-type="login_with" d ...

What causes the "500: Unknown web method" error when JavaScript tries to call a Page WebMethod?

I am encountering an issue with a method in CreateTicket.aspx.cs: [WebMethod()] public static string Categories() { var business = new CategoryBusiness(); var categories = business.ListRootCategories(); return categories.Json(); } Additiona ...

What is the method for adding a default endpoint to Angular $http requests?

In my Angular application, I have a process where variables are retrieved from an environment file and then updated using Grunt. Upon completion of the grunt task, a specific variable is set in environment.js as follows: var envBaseUrl = 'https://live ...

Steps for executing a Node script are as follows:

My task is to execute a node script that will remove an object from an external API. This can be achieved by running the following command: node server.js Customer55555 Upon execution, the specified object should be deleted successfully. To interact wit ...

Why am I receiving undefined for req.user in passportjs?

After setting up passportJS with my node express app, I encountered an issue where the req.user is undefined when making a login/register request. I am not sure what went wrong or if I missed something in the configuration of passport js. In my setup, I us ...

Creating a Dynamic Form with jQuery, AJAX, PHP, and MySQL for Multiple Input Fields

Success! The code is now functional. <form name="registration" id="registration" action="" method="post"> <div id="reg_names"> <div class="control-group"> <label>Name</label> <div class= ...

Should Angular JS pages be requested from the server or not?

I recently delved into learning AngularJS. After inserting Angular code into my HTML page, I attempted to view it in the browser but encountered issues with Angular JS not functioning. However, when I accessed the page through the server, it worked perfe ...

Error with Cross-Origin Resource Sharing (CORS) upon inserting a parameter within an Express application

I'm completely stumped as to why this isn't functioning properly. My express app is deployed on Heroku and here's the code: var urlMetadata = require('url-metadata') var express = require('express') var cors = require( ...

The 'mergeMap' property is not found on the 'Observable<any>' type

Currently, I'm working on an HttpInterceptor within my Ionic 4 application. My goal is to retrieve the Bearer Authorization token stored in local storage. Although I attempted to utilize mergeMap for this task, I kept encountering the following error ...

The constructor in a Typescript Angular controller fails to run

Once the following line of code is executed cockpit.controller('shell', shellCtrl); within my primary module, the shell controller gets registered with the Angular application's _invokeQueue. However, for some reason, the code inside t ...

Transform a binary large object (BLOB) file, specifically a music file, into a .WAV format using NODE.js on the server

I'm having difficulty grasping a basic concept. My Node server is successfully handling POST requests. I am sending a Blob to it (converting the blob to a .wav file). How can I save this Blob as a .wav file on disk? I want to use a music player to ...

Step-by-step guide to forming a rotating half-circle encompassing text

I have a unique shape in the center of my webpage that I want to rotate 360 degrees. Currently, I can adjust the width to make part of it spin, but I'm looking for a way to achieve a full rotation. Ideally, I would like to accomplish this using only C ...

Updating Variables Declared in Parent Component from a Child Component in React using NextJS - A Comprehensive Guide

After reviewing the tutorial on React: Reverse Data Flow to update the variables foodObj, input, and buttonClicked declared in the Parent Component file Main.js, using the child component <SearchAndSuggestion>, I encountered an issue. Here is a snipp ...

Error: Unable to access the 'questionText' property as it is undefined

I encountered an error message stating that my "questionText" could not be read or is not defined. The issue seems to arise in the first code block where I use "questionText", while the intention is to drag it in the second code block. Is there a mistake ...

AngularJS: Assigning a value to an element

I am facing the challenge of automating an iframe using Selenium Webdriver and need to input a value into a text box. Here is the HTML code: <input class="ng-pristine ng-empty ng-invalid ng-invalid-required ng-valid-maxlength ng-touched" id="name" typ ...

The object model being utilized in Angular Formly remains static even after I attempt to reassign it

Using formly, I am able to modify objects retrieved from a server. After making the necessary edits, I save the changes. However, when the server sends back the updated object, I update my model object in formly with this new data. Strangely though, formly ...

Why is gh-pages not recognizing the project directory while looking for resources?

I've encountered an issue with my website that functions perfectly fine locally but when deployed on gh-pages, it results in several 404 errors while attempting to retrieve resources. One such example is a line of CSS for setting the background: back ...

Differentiate the items within a list containing identical divs using JavaScript

Currently, I am expanding my knowledge in HTML, CSS, and JS by incorporating Angular and JQuery. In one of my projects, there is a div labeled "eventBoxes" where multiple divs known as "eventBox" can be added. I have created a template for the eventBox i ...

Using AngularJS to create a form and showcase JSON information

My code is below: PizzaStore.html: <!DOCTYPE html> <html ng-app="PizzaApp"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Delicious pizza for all!</title> ...