<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel xmlns:media="http://search.yahoo.com/mrss/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <title>ABP.IO Stories</title>
    <link>https://abp.io/community/articles</link>
    <description>A hub for ABP Framework, .NET, and software development. Access articles, tutorials, news, and contribute to the ABP community.</description>
    <lastBuildDate>Sat, 03 Oct 2026 02:09:15 Z</lastBuildDate>
    <generator>Community - ABP.IO</generator>
    <image>
      <url>https://abp.io/assets/favicon.ico/favicon-32x32.png</url>
      <title>ABP.IO Stories</title>
      <link>https://abp.io/community/articles</link>
    </image>
    <a10:link rel="self" type="application/rss+xml" title="self" href="https://abp.io/community/rss?member=mahmutgundogdu" />
    <item>
      <guid isPermaLink="true">https://abp.io/community/posts/how-to-use-angular-material-with-form-validation-on-abp-jtheajj3</guid>
      <link>https://abp.io/community/posts/how-to-use-angular-material-with-form-validation-on-abp-jtheajj3</link>
      <a10:author>
        <a10:name>mahmutgundogdu</a10:name>
        <a10:uri>https://abp.io/community/members/mahmutgundogdu</a10:uri>
      </a10:author>
      <category>angular</category>
      <category>abp</category>
      <category>material</category>
      <title>How to use Angular Material with Form Validation on ABP</title>
      <description>The ABP framework (Angular) has its own validation mechanism, which may cause issues with Angular Material. In this article, I will explain how to use ngx-validate with Angular Material components.</description>
      <pubDate>Mon, 24 Jun 2024 13:08:40 Z</pubDate>
      <a10:updated>2026-10-03T00:56:41Z</a10:updated>
      <content:encoded><![CDATA[<h1>How to use Angular Material with Validation On ABP</h1>
<p>The ABP framework (Angular) has its own validation mechanism. default settings  may cause issues with Angular Material. In this example, I want to show how to use ABP client-side validation with Angular Material (ngx-validate).</p>
<h3>Creating project</h3>
<p>I use that settings.
<code>abp new BookStoreMaterial -t app-nolayers -u angular -dbms SQLite --theme basic -csf</code></p>
<p>The Backend and Theme option is a little bit off-topic since I chose the simplest one.</p>
<h3>Add angular material in project.</h3>
<p>To add Angular Material to your project, you can use the ng add command. Open your terminal and navigate to the root directory of your project. Then, run the following command:</p>
<pre><code>ng add @angular/material
</code></pre>
<p>Using this command, you can set up your project to use Angular Material and install all of its dependencies:</p>
<h3>Form Validation</h3>
<p>We have simple form with validation rules</p>
<pre><code class="language-js">this.form = this.formBuilder.group({
  name: ['', Validators.required],
  email: ['', [Validators.required, Validators.email]],
  password: ['', [Validators.required, Validators.minLength(6)]],
});
</code></pre>
<p>The user sees errors when they clicked the submit button. It functions, but the expected visual behavior is out of place.</p>
<p><img src="https://raw.githubusercontent.com/mahmut-gundogdu/abp-material-validation-demo/main/img/1.png" alt="Image" /></p>
<p><code>mat-form-field</code> get access to error component and placed in the dom. See the Angular Material Form Error page to see how it works.
https://material.angular.io/components/form-field/overview#error-messages</p>
<pre><code class="language-html"> &lt;mat-form-field class=&quot;col&quot;&gt;
      &lt;mat-label&gt;First Name&lt;/mat-label&gt;
      &lt;input matInput formControlName=&quot;firstName&quot; /&gt;
       @if (firstName.invalid) {
      &lt;mat-error&gt;{{&quot;AbpValidation::ThisFieldIsRequired&quot; | abpLocalization}}&lt;/mat-error&gt;
        }
    &lt;/mat-form-field&gt;
</code></pre>
<p><img src="https://raw.githubusercontent.com/mahmut-gundogdu/abp-material-validation-demo/main/img/2.png" alt="Step2" />
It's better, yes, but there are two error messages.  NgxValidate created one, and the developer added two.</p>
<p>We can disable NgxValidation using an directive named <code>skipValidation</code>.</p>
<p><img src="https://raw.githubusercontent.com/mahmut-gundogdu/abp-material-validation-demo/main/img/3.png" alt="Step3" /></p>
<p>However, we must add each localization message individually. It is quite repetitive.</p>
<p>Using the <code>validationTarget</code> and <code>ValidationContainer</code> attributes in NgxValidate, we can build error messages. The directive <code>validateContainer</code> is a pointer. For error messages, it defines or marks a parent. The location of the added error message is marked with <code>validationTarget</code>.</p>
<pre><code class="language-html">    &lt;mat-form-field class=&quot;col&quot; validationContainer&gt;
      &lt;mat-label&gt;First Name&lt;/mat-label&gt;
      &lt;input matInput formControlName=&quot;firstName&quot; /&gt;
      &lt;mat-error validationTarget /&gt;
    &lt;/mat-form-field&gt;
</code></pre>
<p>yet my visual issue continues. due to the validation message being inserted by ngx-validate as a sibling.</p>
<p><img src="https://raw.githubusercontent.com/mahmut-gundogdu/abp-material-validation-demo/main/img/4.png" alt="Step4" /></p>
<pre><code class="language-css">mat-error {
  display: none !important;
}
.mat-mdc-form-field-error-wrapper .invalid-feedback{
  display:inline;
}
</code></pre>
<p>it works!</p>
<p><img src="https://raw.githubusercontent.com/mahmut-gundogdu/abp-material-validation-demo/main/img/5.png" alt="Step5" /></p>
]]></content:encoded>
      <media:thumbnail url="https://abp.io/api/posts/cover-picture-source/3a135c89-bcd7-a7c3-e7e4-6c1be9daf35e" />
      <media:content url="https://abp.io/api/posts/cover-picture-source/3a135c89-bcd7-a7c3-e7e4-6c1be9daf35e" medium="image" />
    </item>
  </channel>
</rss>