"Troubleshooting Angular: Uncovering the Root of the Issue with

I have set a specific pattern for the email field which should follow this format:

pattern="^(([^<>()\[\]\.,;:\s@\']+(\.[^<>()\[\]\.,;:\s@\']+)*)|(\'.+\'))@(([^<>()[\]\.,;:\s@\']+\.)+[^<>()[\]\.,;:\s@\']{2,})$"

Additionally, there is a directive that utilizes ngModel on the same field:

<input pattern="^(([^<>()\[\]\.,;:\s@\']+(\.[^<>()\[\]\.,;:\s@\']+)*)|(\'.+\'))@(([^<>()[\]\.,;:\s@\']+\.)+[^<>()[\]\.,;:\s@\']{2,})$" 
                    dir= "ltr"
                    class="form-control sgn-rounded_textbox" 
                    name="emailBox1" 
                    type="email" 
                    ng-model="vm.model.emails.emailField"
                    input-change = vm.mail>

The inputChange directive is as follows:

(function () {
    function inputChange($log, $timeout, $q, appCmdService) {

        return {
            restrict: 'A',
            require: 'ngModel',
            scope: {
                inputChange: '='
            },
            link: function (scope, element, attrs, ngModel) {
                var el = element[0];

                if (checkForENSettings(scope)) {

                    if (ngModel) { 
                        ngModel.$parsers.push(function (value) {
                            if(value){
                                //some logic to change the value....
                                ngModel.$setViewValue(value);
                                ngModel.$render();
                                el.setSelectionRange(start, end);
                                return value;
                            }
                        });
                        ngModel.$formatters.push(function (value) {

                            ngModel.$setViewValue(value);
                            ngModel.$render();

                            return value;
                        });
                    }

                }

                function checkForENSettings(scope){
                    if(scope.inputChange && scope.inputChange.lang === 'en'){
                        return true;
                    }
                }

            }
        };     
}
    angular.module('common').directive('inputChange', inputChange);

})();

The input-change directive functions correctly on fields without a specified pattern. However, when combined with a pattern, the following error occurs:

Cannot assign to read only property 'message' of object '[object DOMException]'

This is followed by:

Error: [$rootScope:inprog] $digest already in progress

Is there a way to effectively utilize both ngModel and pattern on the same input field?

Thank you.

Answer №1

There seems to be a problem with HTML5 input type="email" and accessing Element selectionStart or selectionEnd, as discussed in this issue on - HTML5 input email ans selection.

The issue was resolved by removing the type="email" attribute.

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

Scrolling to specific ID scrolls only in a downward direction

I have been using fullpage.js for my website and I am facing an issue. When I create a link and connect it to an id, everything works perfectly. However, I am unable to scroll back up once I have scrolled down. Here is the HTML code: <a href="#section ...

Struggling to implement my reusable React component within a React Bootstrap modal

I have developed a reusable textarea React component: import React from 'react'; import '../form-input/form-input.styles.scss'; const TextAreaComponent = ({ handleChange, label, ...otherProps }) => ( <div className="group"> ...

What is the best way to tally json elements for every parameter?

My data consists of JSON objects with "Week" and "From" properties: { "Week": 1145, "From": "IN1" }, { "Week": 1145, "From": "IN1" }, { "Week": 1145, "From": "IN2" }, { "Week": 1146, "From": "IN1" }, { "W ...

What is the hierarchy for displaying elements depending on the props?

I have developed a search input component that includes an icon which I want to reposition (either on the left or right side) depending on different scenarios. This input is part of a bootstrap input-group, so modifying the order of elements within my di ...

Express application failed to deploy due to boot timeout error R10

After researching extensively on Stack Overflow and various other websites, I have been unable to solve a problem with my small Express app using ES6 syntax. Upon deploying it to Heroku, I encountered the following error: LOGS : 2021-04-09T12:14:14.688546 ...

Ways to maintain hover functionality when the submenu is visible

My website features a simple table that displays devices and their characteristics. A condensed version of the table can be found in the link below. import "./styles.css"; import { SubMenu } from "./SubMenu"; const subMenuSlice = <S ...

Using DefaultSeo does not override NextSeo in every component

I am looking to dynamically change the Head tag using next-seo. While browser validation will show NEXTSeo for individual pages, Twitter, Firebase's card validation tool, and others will default to next-seo-config.js. Does anyone have a solution? S ...

Next.js is able to generate a unique URL that strictly handles code execution without any visual elements

Currently, I am in the process of developing a new website using NextJS. One issue that has come up involves a password reset verification endpoint. After a user initiates a password reset, it is sent to the API for processing and then redirected back to ...

The controller function is not triggered if the user does not have administrator privileges

I have a code snippet in which my controller function is not being triggered for users who do not have the role of "Admin". Can someone help me identify where I went wrong? Just to clarify, the controller function works fine for users with the role of "Adm ...

When utilizing ng-views within PhoneGap, receiving the origin is restricted due to the Access-Control-Allow-Origin policy

Having trouble getting ng-views to function properly in an Android phone app. When attempting to navigate to one of the views via a hyperlink, I encounter the error message: "Origin is not allowed by Access-Control-Allow-Origin" I have made attempts to m ...

Exploring the possibilities of ReactJS and the sleek design of

How can I alter the background color of a RaisedButton without having the CSS class name appear in the autogenerated div? Here is the button: <RaisedButton className="access-login" label="Acceder" type="submit"/> This is the specified CSS: .acces ...

Leveraging the replace feature within Selenium IDE

After extracting information from a webpage, I found a string that read "price: $30.00" which I saved as "x." What I really needed was just the numbers - "30.00". I attempted to use x.replace(), but unfortunately it didn't work out. If anyone could as ...

When a property is passed as a prop in a Vue component, it is received

https://jsfiddle.net/2xwo87bs/ In order for Vue to properly handle the object prop that is being passed to the component, it is necessary to first convert the string into an actual object. While in the provided snippet I have used JSON.parse() as a qui ...

Launch a new window with the window.open() method and execute a function on the newly opened window

I am having trouble generating a barcode in a new window using the barcode generator script. Despite trying to use window.focus(), I can't get the barcode to appear in the new window. Any assistance on how to generate the barcode in a separate window ...

Error: Trying to access the 'keyboard' property of an undefined object

I am encountering an error message 'Cannot read property 'keyboard' of undefined' and I'm not sure how to fix it. I just want to check if the keyboard is visible on the screen, but this specific line of code seems to be causing the ...

NPM is having trouble locating a shell script

An error is encountered when running npm run build: '.' is not recognized as an internal or external command, operable program or batch file. Here is the npm file that contains relevant scripts: "scripts": { "postinstall": "jspm instal ...

Why is it that PowerShell cannot execute Angular commands?

Recently, I started diving into Angular and encountered an issue using PowerShell in Windows. Every time I run an angular command like: ng new new-app or ng serve I keep getting this error message: ng : File C:\Users\< username >\ ...

Put the code inside a function. I'm new to this

My goal is to encapsulate this code: if($(window).width() > 980) { $(window).on("scroll", function() { if($(window).scrollTop() > 20) { //add black background $(".x-navbar").addClass("active"); $(".x-navbar .desktop ...

Ways to showcase multiple elements using introjs

I am attempting to highlight multiple DOM elements using the JS library intro.js, but I am encountering an issue. It seems that I can only define one element to be highlighted at a time. introjs.setOptions({ steps: [ { ...

fetching indexeddb information using the equivalent of a "WHERE IN (a,b)" query

I've been working on transitioning from websql to indexeddb, but I'm struggling to recreate the SELECT query: "SELECT * FROM tableA WHERE cid ='"+cid+"' AND hid IN("+hid+",1) ORDER BY hid DESC LIMIT 1"; function getMyData(e) { var ...