Issue with validating the date picker when updating user information

Trying to manage user accounts through a dialog form for adding and updating operations, where the type of operation is determined by a variable injected from the main component. Encountered an issue while launching the update process - the date picker triggered a validation error without any specific validation conditions set, resulting in the submit button being disabled. Check out the screenshot of the update form: https://i.sstatic.net/SWNHX.png

Below is the HTML code snippet:

<form [formGroup]="profileForm" class="event-form w-100-p" fxLayout="column" fxFlex>
...
 <div fxFlex="1 0 auto" fxLayout="column" fxLayout.gt-xs="row">

                <mat-form-field appearance="outline" class="pr-sm-8" fxFlex="100">
                    <mat-label>Date of Birth</mat-label>
                    <input matInput [matDatepicker]="startDatePicker"  formControlName="birthday">
                    <mat-datepicker-toggle matSuffix [for]="startDatePicker"></mat-datepicker-toggle>
                    <mat-datepicker #startDatePicker ></mat-datepicker>
                </mat-form-field>

            </div>
...
<div mat-dialog-actions class="m-0 p-16" fxLayout="row" fxLayoutAlign="end center">

        <button  mat-button color="primary"
                class="save-button"
                (click)="onaccept()"
                [disabled]="profileForm.invalid"
                aria-label="ADD">
                {{ActionType}}
        </button>

    </div>

Here is the component.ts code snippet:

profileForm = this.fb.group({
    Last_name: ['' ,Validators.required],
    First_name: ['' ,Validators.required],
    email: ['', [Validators.email,Validators.required]],
    Personnel_code: [,Validators.compose( [Validators.min(1000), Validators.max(9999)])],
    Phone_number: [''],
    birthday: [''],
    address: [''],
    place_of_birth:[''],
    ID_card:['',Validators.compose([Validators.min(10000000), Validators.max(99999999)])],
    Gender:[''],
    License_number:[''],
    Department: ['',Validators.required]
  });
  constructor(public dialogRef: MatDialogRef<EditNewChauffeursComponent>, private fb: FormBuilder)
  ngOnInit() {
       this.setdefaultformvalues(this.indata.SendData);
}
 setdefaultformvalues(row) {
    this.profileForm.patchValue({
      Last_name: [row.FirstName],
      First_name: [row.LastName],
      email: [row.Email],
      Personnel_code: [row.DriverCode],
      Phone_number: [row.Tel],
      birthday: [''],
      address: [row.Address],
      place_of_birth:[row.BirthPlace],
      ID_card:[row.CIN],
      Gender:[row.DriverLicenseType],
      License_number:[row.DriverLicenseNumber],
      Department: [row.DepartmentId]
    });

  }

Answer №1

When working with the function setdefaultformvalues, make sure to include the following:

birthday: null,

as opposed to

birthday: [''],

Answer №2

Could you please add a console log for the profileForm once it has been filled out? Take a look at the controls object within it to see all of your controls. Specifically check the birthday control to see if there is an error key present. Investigate what the error could be.

[Here is an example of how this should work]

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

The name '__DEV__' is not discoverable at the moment

While working with the mobx library in my project, I encountered an issue after installing it using npm. Upon exploring the mobx/src/error.ts file within the node_modules folder, I came across a compile time error on line 78: const errors: typeof niceError ...

VPS mysteriously terminates TypeScript compilation process without any apparent error

I've encountered an issue while trying to compile my TypeScript /src folder into the /dist folder. The process works smoothly on my local machine, but when I clone the repo onto my VPS (Ubuntu Server 22.04), install npm, and run the compile script, it ...

Angular 12 update appears to be causing an issue where CanActivate is not being triggered

After upgrading to angular 12, I am encountering a problem where my application displays a white/blank page upon starting. The issue lies in the fact that the canActivate method within my "RedirectGuard", which implements CanActivate, is no longer being t ...

Issues arising while fetching data with Angular httpClient

Hey there! I'm currently working with a basic controller that is returning some simple data. Here's the code snippet: [HttpGet("[action]")] public AppSettings GetStuff() { var stuff = new Stuff { Dummy = "Hi" }; return stuf ...

What causes inability for JavaScript to access a property?

My current coding project involves the usage of typescript decorators in the following way: function logParameter(target: any, key : string, index : number) { var metadataKey = `__log_${key}_parameters`; console.log(target); console.log(metadataKey ...

Issue with the datepicker not toggling properly in Angular-UI 0.11.0, only opens

I am struggling with implementing 2 datepickers using Angular UI version 0.11.0. Here is my HTML code: <span ng-if="periods.period == 10"> <input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="cdate.customStartDate" is-open="opened1" ...

Quick + Vue Router - Lazy Loading Modules

For my personal project, I am using Vite alongside Vue 3 and have integrated vue-router@4 for managing routes. Since all of my modules share the same set of routes, I created a helper function: import { RouteRecordRaw } from 'vue-router' import p ...

What is the best way to store and recall user selections from a dropdown menu using PHP?

Newbie in the house. I managed to store my user's choice from a select menu, but now it seems like the validation is not working as expected. How can I resolve this issue? This is the snippet of code I'm using for validation: <?php $color ...

Which location can I find my 'bundles' folder in Angular 2, NPM, and Visual Studio 2015?

Each guide mentions /node_modules/angular2/bundles/... I'm puzzled why I can't find the 'bundles' directories for Angular or any library obtained from NPM within Visual Studio 2015? Downloaded from NPM "dependencies": { "angular ...

Is it possible to align a row so that it is centered based on one of the columns in the row?

Calling all experts in CSS and HTML: Let's say I have 3 columns in a row, each with a different size (refer to the image). Now, picture this - I want to center the 2nd column right in the middle of my page. If I simply use justify-content: center to ...

Customizable TypeScript interface with built-in default key value types that can be easily extended

One common pattern that arises frequently in my projects involves fetching values and updating the UI based on the 'requestStatus' and other associated values. type RequestStatus = | 'pending' | 'requesting' | 'succ ...

The error was thrown by the internal module loader in Node.js at line 1029

I encountered this Console Error - "Error: Cannot find module". Below is the detailed error message in the console. Any solutions? node:internal/modules/cjs/loader:1029 throw err; ^ Error: Cannot find module '/home/hiranwj/list' at Mo ...

Assigning variables within Redux saga generators/sagas

Consider this scenario: function* mySaga(){ const x = yield call(getX) } The value of const x is not determined directly by the return value of call(getX()). Instead, it depends on what is passed in mySaga.next(whatever) when it is invoked. One might a ...

What is the best way to test the validity of a form while also verifying email availability?

I am currently working on implementing async validation in reactive forms. My goal is to disable the submit button whenever a new input is provided. However, I am facing an issue where if duplicate emails are entered, the form remains valid for a brief per ...

Is there a way to determine if a tuple is of infinite or finite length?

Is there a way to determine if a tuple is finite or infinite? I've been working on a solution, but it doesn't cover all cases: type IsFinite<T extends any[], Finite = true, Infinite = false> = T extends [] ? Finite : T extends (infer E ...

When attempting to publish an index.d.ts file using npm, the module is

We are currently in the process of developing an npm package that will serve as the foundation for most of our projects. However, we have encountered some issues that need to be addressed: The index.d.ts file of our base npm package is structured as shown ...

Can dynamic attributes be used with ternary operators in Angular?

I attempted to alter the id of a div using Angular and implemented the following code: <div [id]="'item_' + (itemName !== undefined ? itemName.replace(' ', '-').toLowerCase() : '')"> However, when I run my te ...

default selection in angular 2 dropdown menu

I'm struggling to figure out how to set a default value for a select dropdown list effortlessly. Here's my current code: <select class="form-control" ngControl="modID" #modID="ngForm"> <option *ngFor="let module of modules" [val ...

Ending an HTTP subscription in RxJS

Within my Angular application, I am eager to implement the ability to cancel an HTTP request made with RxJS. Here is the specific scenario: this.componentActive = true; onSave() { this.myService.save(this.formData).takeWhile(() => this.componentA ...

Length of Angular events

I am embarking on the journey of building an Angular web application and I find myself in need of tracking various performance time-related data: The duration between clicking a button and the API call being initiated The duration between the API call be ...