From 29926b94fe1c53a031d7fb1f236520e5367b6a0d Mon Sep 17 00:00:00 2001 From: surya Date: Thu, 28 Apr 2022 16:12:42 +0530 Subject: [PATCH] Custom Notification -single msg,validation --- .../dynamic-notify.component.html | 10 +++++-- .../dynamic-notify.component.ts | 26 ++++++++++++------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/ng6-seed/src/app/layouts/dynamic-notify/dynamic-notify.component.html b/ng6-seed/src/app/layouts/dynamic-notify/dynamic-notify.component.html index 0d42a0c57..08c4cfd4a 100644 --- a/ng6-seed/src/app/layouts/dynamic-notify/dynamic-notify.component.html +++ b/ng6-seed/src/app/layouts/dynamic-notify/dynamic-notify.component.html @@ -43,13 +43,16 @@ Select All {{option.first_name}} + +
+ +
-
Enter Text +
+ +
- + diff --git a/ng6-seed/src/app/layouts/dynamic-notify/dynamic-notify.component.ts b/ng6-seed/src/app/layouts/dynamic-notify/dynamic-notify.component.ts index 665af8f6d..6231590b7 100644 --- a/ng6-seed/src/app/layouts/dynamic-notify/dynamic-notify.component.ts +++ b/ng6-seed/src/app/layouts/dynamic-notify/dynamic-notify.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit, ViewChild } from '@angular/core'; -import { FormBuilder, FormGroup } from '@angular/forms'; +import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { MatOption } from '@angular/material'; import { UserService } from 'app/settings/service/user.service'; @@ -12,8 +12,8 @@ import { UserService } from 'app/settings/service/user.service'; }) export class DynamicNotifyComponent implements OnInit { selectedAll:any={pdofficer:false} - pdofficer: any; - msg: any; + // pdofficer: any; + // msg: any; pdofficerlist: any = []; selectedItems:any=[]; dropdownSettings:any={}; @@ -21,6 +21,9 @@ export class DynamicNotifyComponent implements OnInit { customnotifyform: FormGroup; @ViewChild('allSelected') private allSelected: MatOption; + pdofficer = new FormControl("", [Validators.required]); + msg = new FormControl("", [Validators.required]); + constructor( public users:UserService,private _fb:FormBuilder) { @@ -29,8 +32,11 @@ export class DynamicNotifyComponent implements OnInit { ngOnInit() { this.customnotifyform = this._fb.group({ - pdofficer:[''], - msg:[''], + // pdofficer:[''], + // msg:[''], + pdofficer: this.pdofficer, + msg: this.msg + }) this.getPdofficersList() @@ -103,10 +109,10 @@ toggleAllSelection() { onSubmitUserDetails(param) { console.log(param) let configdata; - param.pdofficer.shift() + // param.pdofficer.shift() console.log(param.pdofficer.length -1 + ' '+ this.pdofficerlist.length) - if ((param.pdofficer.length) == this.pdofficerlist.length){ - configdata = { "records":{ "user_id":0,"msg":param.msg} } + if ((param.pdofficer.length - 1) == this.pdofficerlist.length){ + configdata = { "records":{ "user_id":[0],"msg":param.msg} } } else{ configdata = { "records":{ "user_id":param.pdofficer,"msg":param.msg} } @@ -122,7 +128,9 @@ toggleAllSelection() { } - + public hasError = (controlName: string, errorName: string) => { + return this.customnotifyform.controls[controlName].hasError(errorName); + }; }