The binding of values entered through a touch event is unsuccessful with ng-model

In my Angular app, I have integrated a JQuery + Bootstrap keyboard that is designed exclusively for touch input. If I try to use the mouse to click on the keys, the keyboard closes without registering any keystrokes, as it is programmed to close on click events.

Mobile-first-Virtual-Keyboard-Plugin-With-JQuery-Bootstrap

I am encountering an issue when trying to bind input from a text box in my controller using ng-model as shown in the following code:

<input autocomplete="false" class="textInputSeeThrough keyboard"
                    ng-model="patientNIC" type="text" id="nic"
                    name="patientNICTxtbox" autofocus
                    placeholder="--- ENTER NIC NUMBER ---">

The input data does not bind correctly. However, if I manually access the element value using plain JavaScript instead of relying on $scope in the controller, I am able to retrieve the value successfully.

var val1 = $scope.patientNIC; // this doesn't work
var val2 = document.getElementById("nic"); // this works

alert(val1);
alert(val2.value);

This inconsistency indicates that the issue is not related to the Keyboard itself. Could there be a potential problem with AngularJS interacting with touch events? After researching, I have not found any known issues. Can anyone provide insights into why this discrepancy is occurring? Thank you in advance.

Answer №1

One thing to remember is that Angular doesn't automatically detect changes in input. To make sure any changes are recognized, they need to be enclosed in $apply or $timeout.

Take a look at this helpful resource: Update Angular model after setting input value with jQuery

Answer №2

Don't stress about it, simply use jQuery or Javascript to set values to input elements. To do this, copy and paste the following script into your HTML block or JS file (jQuery):

    !function (n, t) { "use strict"; var r = n.fn.val; n.fn.val = function (n) { if (!arguments.length) return r.call(this); var e = r.call(this, n); return t.element(this[0]).triggerHandler("input"), e } }(window.jQuery, window.angular);

We also don't need to assign values to ng object or trigger the input individually.

Cheers!

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

Error: Node.js/Express unable to connect to static assets

I recently deployed my Express application to a production server and encountered an issue with serving static assets. All of my assets are located in the /public directory, and I am using the following code to call the static middleware: // config.root ...

Is there a method available within the Collada loader to extract multiple meshes from the scene object?

Recently, I delved into some experimental work with Blender and the Collada Loader in three.js. Within my Blender project, I have three distinct objects, but when using the loader in three.js, I can only manipulate them as one single scene object. While ev ...

When using slideToggle() in conjunction with elements created using jQuery's append(), there is no automatic repositioning

Struggling with using slideToggle(), I'm facing an issue where the DOM elements do not get pushed down as expected; instead, they overlap. Despite trying multiple versions, I haven't been able to resolve this issue. The problem arises when creati ...

Optimize performance by reindexing multi-dimensional arrays in PHP using jQuery

[{ "sys_id": "2015-07-018", "account_id": "2015-07-018", "Names": [{ "fname": "Jackie", "mname": "Lee", "lname": "Chan", "suffix": "Jr", "city": "Tokyo", "town": "Shinagawa-ku", "dstrct": ...

Tips for handling race conditions in webdriver

My app uses a combination of angular and asp.net, but I'm facing an issue with the home page redirection. Initially, all routing was handled by the angular app itself, but due to certain requirements, we had to change it so that the home page redirect ...

Ways to split arrays in JavaScript

With a dataset of 82 items, I am trying to divide them into groups of 10 for one file and 2 for another. Can someone assist me with separating the array accordingly? Here is my current code: var data = []; data.forEach(function(i,v) { if((v != 0) && ...

Checking the boxes in javascript

Hey there, I'm a JavaScript newbie and struggling to validate my check-boxes. Despite looking at multiple examples, the concept is still not sinking in for me. Could someone please provide guidance on how to properly validate my check-boxes? Additiona ...

An error occurred with the datepicker: Unable to connect to 'bsValue' as it is not recognized as a property of 'input'

Despite importing DatepickerModule.forRoot() in my Angular unit test, I am encountering the following error: Error: Template parse errors: Can't bind to 'bsConfig' since it isn't a known property of 'input'. (" ...

Is there a way to combine several WAV audio blobs into one cohesive file?

Issue I'm Facing: I am attempting to combine multiple blob audio files into a single blob and then download it on the page. My Attempts So Far: I have tried to merge the Audio blobs using the following methods: Method - 1: const url = window.URL.c ...

Access the URL parameter in react-router and incorporate it into the Component

I need to retrieve the id parameter from the URL in my react-router setup (App.js): import React from "react"; import ReactDOM from "react-dom"; import Main from "./ui.js"; import Master from "./master.js"; import FireCess from "./FireCess"; import { ...

Anonymized Score Reporting through Google Analytics analytics.js

Recently, I've been working on setting up Google Analytics for tracking my web game. Everything seems to be working fine, except for one issue - when I check my custom report the next day after testing the game, I notice that all the scores have been ...

Angular 2 issue with nested form elements

Looking to build a form that includes nested sub/child components within it. Referring to this tutorial: https://scotch.io/tutorials/how-to-build-nested-model-driven-forms-in-angular-2 https://plnkr.co/edit/clTbNP7MHBbBbrUp20vr?p=info List of modificatio ...

Display a popup box upon receiving the response from an AJAX request

I have successfully implemented an Ajax code that delivers the desired result. Now, I am looking to enhance this code so that when a response is received from Ajax, a popup/modal box will automatically open. Currently, I can manually trigger the opening o ...

if the arguments for a javascript function are not provided

Currently, I am in the process of learning JavaScript through a book called "Visual Quickstart Guide". However, I have encountered a challenge with understanding the logic behind a particular code snippet. In the function definition below, it appears that ...

How to insert an HTML element in between multiple list items using jQuery

I have a variety of div elements that I want to group together using jQuery's append method: Here are the initial div elements: <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div& ...

What is the best way to reset input autocomplete styles?

I am working with a basic Bootstrap form that is submitted using JavaScript. Upon clicking the submit button, the data is processed and the input values are reset without the need to reload the page: if( json.success ) { $('#form_sendemail').f ...

Ensure that the query is properly separated from the body when making an Axios request

While working on my code, I encountered an issue when making a PUT request to the backend of the application using Axios. The problem arose when the method in the user service, responsible for handling the request, returned a null response. Here is the met ...

Is there a way for me to differentiate between numbers and words (elements in quotes) within an array?

Here's the scenario: I have an array named this.someArray. this.someArray = ["Word", "123", "456"] The content of this.someArray is generated dynamically, so the elements are not hardcoded. My goal is to convert all numeric items into actual numbers ...

Sort through various table columns

I am currently utilizing a data table component from Framework7, which is being generated dynamically with JSON data. My goal is to make the column filter input functional within the table. So far, I have succeeded in implementing the filter for the first ...

Can a single endpoint be used to provide files to web browsers and data to REST requests simultaneously?

I recently completed a tutorial that lasted 7 hours on creating a blog, following it almost completely. The only step I skipped was setting up separate client/server hosting as suggested in the tutorial. Instead, I have a single Heroku server serving the c ...