Validating patterns in Angular without using a form

Seeking guidance on validating user input in Angular6 PrimeNG pInputText for a specific URL pattern, such as , possibly triggered on blur event.

This particular field used to be part of a form but has since been relocated to a more complex 6-part form interface. Clicking a button in this new setup should retrieve data related to the URL from a database and populate other fields in the form for editing purposes.

Within a team management application for a bank, this input field is intended for entering and validating resources like JIRA or Bitbucket repositories.

What would be the best approach to implement this validation? I've come across mentions of using the ngForm directive, however, I am concerned about potential interference with the existing complex form or any unintended side effects. Could having two forms on one screen cause conflicts?

Additionally, there is a 'pattern' attribute available in the input field, so it may be possible to achieve the validation without relying on a full form setup.

Your advice and assistance on this matter are greatly appreciated.

Thank you in advance, Oleg.

Answer №1

  1. You have the ability to create multiple forms on a single page in Angular without encountering any issues.

  2. Managing this situation is simple even without a form. If you need to utilize blur, you can easily implement it as shown below:

    <input type="text" pInputText placeholder="url" [(ngModel)]="data.model"
    (blur)="checkInputValue(data.model)"/>
    

In the component.ts file:

checkInputValue(value: string){
    // assume value is "https://www.google.com";
    var patt = new RegExp(/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/gm);
    var res = patt.test(value);
    if(res){
    //fetch data from database and populate the second form
    }
}

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

What is the process for retrieving the parent component from projected content?

One interesting aspect to explore is the varying behaviors of input based on its 'parent' element. The structure I am referring to is as follows: In my first example, the input is nested within the app-chip-list component. APP COMPONENT HTML & ...

Angular 4 encounters a hiccup when a mistake in the XHR request brings a halt to a

In my Angular 4 application, I have implemented an observable that monitors an input field. When it detects a URL being entered, it triggers a service to make an XHR request. Observable.fromEvent(this._elementRef.nativeElement, 'input') .debou ...

Troubleshoot TypeScript API within Angular 12 using Chrome debugger

I'm having trouble finding a solution on SO. Can anyone help me debug and check the code snippet below for hello? getHero(): void { const id = parseInt(this.route.snapshot.paramMap.get('id') !, 10); this.heroService.getHero(id) .sub ...

implementing a default reducer using ngrx schematics

I'm having trouble creating a reducer using the ngrx schematics command ng generate @ngrx/schematics:reducer ZipCodes --group When I generate the reducer file, it does not include a default implementation of the reducer export const reducer = createR ...

What could be causing the TypeScript class property to be undefined?

Below is the code snippet I am working with: class FeedbackController { public homePage(req, res){ this.test(); res.send('Welcome to feedback service'); } private test(){ console.log('test called'); } } export de ...

What are the steps to implement the `serialport` library in `deno`?

After tinkering with Deno to extract readings from an Arduino, I encountered a roadblock when it came to using the serialport library correctly. Here is what I attempted: According to a post, packages from pika.dev should work. However, when trying to use ...

How can a child component class in Angular 2 be initialized when extending a parent class?

Let's consider a scenario where we have a component called ChildComponent that extends from the Parent class. How do we go about initializing the ChildComponent class? In Angular 2, when this component is used in HTML, it automatically invokes the Chi ...

Issue with displaying value upon component initialization

I have a numeric value that needs to be displayed immediately upon the component loading. The value is calculated by multiplying a drop-down selection with another stored value in a cache. Take a look at my code snippet: ctc = 50000; ngOnInit() { ...

Typing Redux Thunk with middleware in TypeScript: A comprehensive guide

I recently integrated Redux into my SPFx webpart (using TypeScript), and everything seems to be working fine. However, I'm struggling with typing the thunk functions and could use some guidance on how to properly type them. Here's an example of ...

The 'posts' binding element is assumed to have a type of 'any' by default

Currently, I'm working on a code project that involves graphql, react, and typescript. In the middle of the process, I encountered an error message stating "Binding element 'posts' implicitly has an 'any' type." I am unsure about w ...

Pictures are not visible on mobile devices

Currently, I am utilizing Ionic 2 for my project. While the images are displaying correctly on the browser, they are not showing up on the device. This issue has been perplexing me. I attempted to resolve this problem by using the following code: <i ...

How can I retrieve all the recipes associated with a specific user (id) using ASP.NET Core 3.1.1 MVC and Angular?

Currently delving into ASP.NET MVC, I am immersed in building a single-page application using ASP.NET Core 3.1.1 with APIs. Within my User.cs file, there exists a collection of the user's Recipes. Specifically, within my User class, there is a prope ...

Integrating Angular Material's table-expandable-rows and table-wrapped features, this implementation introduces unique expand details. However, it currently does not display the custom

I attempted to develop a component that merges table-expandable-row and table-wrapped functionalities, utilizing ngTemplateOutletContext to include custom details. Unfortunately, the implementation did not yield the desired results. For reference, here is ...

Setting a timer in NGRX to control the interval between two actions

I am currently working with Angular and NGRX, and I have a requirement to implement a timer between two actions. The timer should start when the first action is triggered and stop when the second action occurs. I need to be able to store this timer in a gl ...

Managing the token prior to the page loading: best practices

Implementing JWT for authentication without a login page has posed some challenges for me. The issue arises when the site loads and immediately starts with the GET methods to load content before authenticating and saving the token in local storage. The pr ...

Enriching HtmlElement with a type property using TypeScript

Check out my TypeScript code snippet below: let script: HTMLElement = document.createElement("script"); script.appendChild(document.createTextNode(` { "json": "property" } `)); script.id = 'appContextModel'; document.body.appendChild(scr ...

Unfortunately, the package "error-ex" could not be found when attempting to access it through the npm registry

I am encountering an issue while trying to install npm package dependencies in my Angular application. The error message I receive is related to "error-ex@^1.2.0". Can anyone provide guidance on how to resolve this problem? npm ERR! code E404 npm ERR! 404 ...

Challenges with overwriting TailwindCSS classes within a React component library package

I just released my very first React component on NPM. It's a unique slider with fractions that can be easily dragged. Check it out here: Fractional Range Slider NPM This slider was created using TailwindCSS. During bundling, all the necessary classe ...

Angular web application can retrieve JSON data from a web API controller, allowing for

I'm currently utilizing ASP.NET Core on the backend and Angular on the frontend. My API delivers data in JSON format from the backend. I've set up a service to fetch the API data, but it's returning 'undefined' at the moment. emp ...

The element type 'ReactElement<any>' does not match a JSX element constructor function. 'undefined' cannot be assigned to type 'Element | null'

After attempting the suggested fix of deleting node_modules/ and yarn.lock, then reinstalling everything, I still cannot resolve the issue. I am currently developing a basic router that renders children based on a certain prop: import React, { Fragment } ...