Updating ng-model upon paste command in Safari browser encountering issues

When typing text character by character into a search textbox, everything works fine. However, when pasting data directly into the textbox, the ng-model does not get updated. This issue only occurs in the safari browser.

Here is the HTML code:

<div class="div-input pull-left" ng-submit="submitFilterForm()" ng-class="{ 'filter-dropdown-adjustment' : showFilterState() }">
            <input type="text" class="filter-input" ng-model="query" my-enter="submitFilterForm()" auto-focus />
        </div>

The custom directive 'my-enter' handles the click or press of the enter key.

This is the content of the directive:

    'use strict';

  define([
'angular',
'./module',
      ], function(angular, directives) {

/**
 * Like ngShow but uses CSS visibility instead of display
 */
directives.directive('myEnter', [
    function() {
        return function(scope, element, attrs) {
            element.bind("keydown keypress", function(event) {
                if (event.which === 13) {
                    scope.$apply(function() {
                        scope.$eval(attrs.geEnter);
                    });
                    event.preventDefault();
                }
            });
        };
    }
])

This JavaScript file contains a $watch function on the ng-model for the textbox:

       $scope.$watch("query", function(name) {
            $scope.validationError = false;
            console.log("value of query is", name);
            filterStateService.updateSearchQuery(name);
        });

Answer №1

Take a look at this code snippet. I integrated the ng-paste functionality

<!DOCTYPE html>
<html>
<head>
  <script src="https://code.angularjs.org/1.4.12/angular.js"></script>
  <script>
    var app = angular.module('myApp', []);
    app.controller('mainController', function($scope) {
    
    $scope.handlePaste =function(e){
      setTimeout(function(){
      $scope.query = e.target.value;
      console.log(e.target.value,"val")
     },10)
      
    }
    });
  </script>
</head>

<body ng-app="myApp">
  <div ng-controller="mainController">
    <input type="text" ng-paste="handlePaste($event)" ng-model="query" />
{{query}}

  </div>
</body>

</html>

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

Setting a class in AngularJS when there is a change in ng-repeat with pagination

I am currently attempting to assign a class to an item in a paginated list by simulating a click on the element within the directive's link property: link : function (scope, element, attrs) { element.bind('click', function () { ...

The repairDatabase function cannot be found in the Collection.rawDatabase() method

Seeking guidance on repairing a database within Meteor. Currently executing the following code: Meteor.methods({ 'repairDB'(){ Users.rawDatabase().repairDatabase(); return true; } }); Encountering the following error: I20170630-18: ...

How do you effectively select tabs that are enabled using jQuery UI?

Is there a way to retrieve all the tabs that are currently enabled while multiple tabs exist and some are disabled within a jquery ui tab interface? ...

Angular's ng-bind-html directive for embedding SVG content does not function properly in Internet Explorer

We're in the process of developing an application using angular.js, which involves a large svg-image containing numerous other svg-images and shapes. One major issue we've encountered is that Internet Explorer (even version 11) is refusing to bi ...

I am having trouble getting Google Maps to load

Why does the map on my website only load when the browser window is resized? Below is the JavaScript code being used: <div class="map-cont"> <div id="map" class="location-container map-padding" style="width:100%;height:400px;background:y ...

Issue with Bootstrap 4.2 modal: Unable to edit input fields, button cannot be clicked, modal does not close

https://i.sstatic.net/vHnVG.png https://i.sstatic.net/MhU3f.png Utilizing Bootstrap 4.2.1, I have a modal that opens via a specific link: <a href="#" data-toggle="modal" data-target="#inviteByEmailPopup" data-backdrop="false" data-keyboard="false"> ...

Have you ever encountered the orientationchange event in JavaScript before?

When does the orientationchange event trigger in relation to window rotation completion? Is there a way to fire an event before the operating system initiates the integrated window rotation? Edit: For example, can elements be faded out before the rotation ...

Encountering an issue with blogs.map function in a Next.js application

import Head from 'next/head' import { useState } from 'react' import Image from 'next/image' import styles from '../styles/Home.module.css' const Home = (props) => { const [blogs, setblogs] = useState(props.dat ...

Dealing with errors in AngularJS factory servicesTips for managing errors that occur

Factory code app.factory('abcFactory', function ($http, Config, $log) { var serviceURL = Config.baseURL + '/results'; return{ results:function() { var promise = $http({ method: 'GET&apos ...

What is causing my Li elements to be unchecked in REACT?

Why is the 'checked' value not changing in my list? I'm currently working on a toDo app Here are my State Values: const [newItem, setNewItem] = useState(""); const [toDos, setToDos] = useState([]); This is my function: funct ...

What is the best way to save a token value to a JavaScript file on my local storage

Hello, I am new to Nodejs and have implemented passportjs token-based authentication. When a user logs in, a token is provided for each user. Now, I want to perform certain operations based on the users who have token values. For example, if a user wants t ...

Using scope in ng-style to manipulate a portion of a CSS property value in Angular

I've been attempting to add a border using ng-style, but I'm struggling to figure out how to concatenate the value from the scope variable. None of the methods below seem to be working for me: <div ng-style="{'border-top' :'1p ...

Exploring AngularJS ng-repeat features for custom attribute settings

I'm currently facing a challenge in removing multiple repetitive divs by utilizing ng-repeat. <!-- I have 21 of these --> <div class="table-row"> <span class="glyphicon glyphicon-wrench"></span> <label>Chlo ...

I'm confused why this particular method within a class is not being inherited by the next class. Rather than seeing the expected extension, I am presented with - [Function (

Working fine with the Person class, the register() function displays the correct return statement when logged in the console. However, upon extending it to the Employee class, instead of the expected return statement, the console logs show [Function (anon ...

What is the best way to call a method of a JavaScript object after calling a different method?

Upon frequently encountering this jQuery code snippet, I decided to simplify it into one level action as illustrated in the following code. function $(id) { var $ = document.getElementById(id); $.action1 = function() { }; return $; } Now ...

Node scripts and node bins are causing errors in Vue.js when running npm

While attempting to run my Vue project with the command npm run serve I encountered an error message that read: [email protected] serve /home/numan/Desktop/vue-getting-started/07-accessing-data/begin/vue-heroes vue-cli-service serve sh: 1: vue- ...

What is the method for retrieving the values of multiple numbers entered in table rows using ASP?

I am trying to customize an input field so that the client can add or delete N number of input fields as needed. While I have successfully implemented adding input fields, I am facing difficulty in retrieving values from these dynamically added text fields ...

Utilizing Axios recursion to paginate through an API using a cursor-based approach

Is there a way to paginate an API with a cursor using axios? I am looking to repeatedly call this function until response.data.length < 1 and return the complete array containing all items in the collection once the process is complete. Additionally, I ...

Variations between objects?

There are two different methods for using objects in programming. I am curious to understand if the difference lies in the syntax or if there is more to it. Method 1 body(data) = { item1: data.val1; item2: data.val2; item3: data.val3; } Meth ...

Are there any additional performance costs associated with transmitting JSON objects instead of stringified JSON data through node.js APIs?

When developing node.js APIs, we have the option to send plain JSON objects as parameters (body params). However, I wonder if there is some extra overhead for formatting. What if I stringify the JSON before sending it to the API and then parse it back to i ...