@@ -41,9 +41,9 @@ import { NzColorPickerFormatType, ValidFormKey } from './typings';
4141 changeDetection : ChangeDetectionStrategy . OnPush ,
4242 imports : [ ReactiveFormsModule , NzSelectModule , NzInputModule , NzInputNumberModule ] ,
4343 template : `
44- <div [formGroup]="validateForm" class="ant-color-picker-input-container">
44+ <div class="ant-color-picker-input-container">
4545 <div class="ant-color-picker-format-select">
46- <nz-select formControlName=" isFormat" nzBorderless nzSize="small">
46+ <nz-select [formControl]="validateForm.controls. isFormat" nzBorderless nzSize="small">
4747 <nz-option nzValue="hex" nzLabel="HEX" />
4848 <nz-option nzValue="hsb" nzLabel="HSB" />
4949 <nz-option nzValue="rgb" nzLabel="RGB" />
@@ -55,15 +55,15 @@ import { NzColorPickerFormatType, ValidFormKey } from './typings';
5555 @case ('hex') {
5656 <div class="ant-color-picker-hex-input">
5757 <nz-input-wrapper nzPrefix="#">
58- <input nz-input nzSize="small" formControlName=" hex" />
58+ <input nz-input nzSize="small" [formControl]="validateForm.controls. hex" />
5959 </nz-input-wrapper>
6060 </div>
6161 }
6262 @case ('hsb') {
6363 <div class="ant-color-picker-hsb-input">
6464 <div class="ant-color-picker-steppers ant-color-picker-hsb-input">
6565 <nz-input-number
66- formControlName=" hsbH"
66+ [formControl]="validateForm.controls. hsbH"
6767 [nzMin]="0"
6868 [nzMax]="360"
6969 [nzStep]="1"
@@ -73,7 +73,7 @@ import { NzColorPickerFormatType, ValidFormKey } from './typings';
7373 </div>
7474 <div class="ant-color-picker-steppers ant-color-picker-hsb-input">
7575 <nz-input-number
76- formControlName=" hsbS"
76+ [formControl]="validateForm.controls. hsbS"
7777 [nzMin]="0"
7878 [nzMax]="100"
7979 [nzStep]="1"
@@ -84,7 +84,7 @@ import { NzColorPickerFormatType, ValidFormKey } from './typings';
8484 </div>
8585 <div class="ant-color-picker-steppers ant-color-picker-hsb-input">
8686 <nz-input-number
87- formControlName=" hsbB"
87+ [formControl]="validateForm.controls. hsbB"
8888 [nzMin]="0"
8989 [nzMax]="100"
9090 [nzStep]="1"
@@ -98,13 +98,31 @@ import { NzColorPickerFormatType, ValidFormKey } from './typings';
9898 @default {
9999 <div class="ant-color-picker-rgb-input">
100100 <div class="ant-color-picker-steppers ant-color-picker-rgb-input">
101- <nz-input-number formControlName="rgbR" [nzMin]="0" [nzMax]="255" [nzStep]="1" nzSize="small" />
101+ <nz-input-number
102+ [formControl]="validateForm.controls.rgbR"
103+ [nzMin]="0"
104+ [nzMax]="255"
105+ [nzStep]="1"
106+ nzSize="small"
107+ />
102108 </div>
103109 <div class="ant-color-picker-steppers ant-color-picker-rgb-input">
104- <nz-input-number formControlName="rgbG" [nzMin]="0" [nzMax]="255" [nzStep]="1" nzSize="small" />
110+ <nz-input-number
111+ [formControl]="validateForm.controls.rgbG"
112+ [nzMin]="0"
113+ [nzMax]="255"
114+ [nzStep]="1"
115+ nzSize="small"
116+ />
105117 </div>
106118 <div class="ant-color-picker-steppers ant-color-picker-rgb-input">
107- <nz-input-number formControlName="rgbB" [nzMin]="0" [nzMax]="255" [nzStep]="1" nzSize="small" />
119+ <nz-input-number
120+ [formControl]="validateForm.controls.rgbB"
121+ [nzMin]="0"
122+ [nzMax]="255"
123+ [nzStep]="1"
124+ nzSize="small"
125+ />
108126 </div>
109127 </div>
110128 }
@@ -114,7 +132,7 @@ import { NzColorPickerFormatType, ValidFormKey } from './typings';
114132 @if (!nzDisabledAlpha) {
115133 <div class="ant-color-picker-steppers ant-color-picker-alpha-input">
116134 <nz-input-number
117- formControlName=" roundA"
135+ [formControl]="validateForm.controls. roundA"
118136 [nzMin]="0"
119137 [nzMax]="100"
120138 [nzStep]="1"
@@ -137,18 +155,6 @@ export class NzColorFormatComponent implements OnChanges, OnInit {
137155 @Output ( ) readonly formatChange = new EventEmitter < { color : string ; format : NzColorPickerFormatType } > ( ) ;
138156 @Output ( ) readonly nzOnFormatChange = new EventEmitter < NzColorPickerFormatType > ( ) ;
139157
140- validatorFn ( ) : ValidatorFn {
141- return ( control : AbstractControl ) : ValidationErrors | null => {
142- const REGEXP = / ^ [ 0 - 9 a - f A - F ] { 6 } $ / ;
143- if ( ! control . value ) {
144- return { error : true } ;
145- } else if ( ! REGEXP . test ( control . value ) ) {
146- return { error : true } ;
147- }
148- return null ;
149- } ;
150- }
151-
152158 validateForm : FormGroup < {
153159 isFormat : FormControl < NzColorPickerFormatType | null > ;
154160 hex : FormControl < string | null > ;
@@ -161,7 +167,7 @@ export class NzColorFormatComponent implements OnChanges, OnInit {
161167 roundA : FormControl < number > ;
162168 } > = this . formBuilder . nonNullable . group ( {
163169 isFormat : this . formBuilder . control < NzColorPickerFormatType > ( 'hex' ) ,
164- hex : this . formBuilder . control < string > ( '1677FF' , this . validatorFn ( ) ) ,
170+ hex : this . formBuilder . control < string > ( '1677FF' , hexValidator ) ,
165171 hsbH : 215 ,
166172 hsbS : 91 ,
167173 hsbB : 100 ,
@@ -251,3 +257,13 @@ export class NzColorFormatComponent implements OnChanges, OnInit {
251257 }
252258 }
253259}
260+
261+ const hexValidator : ValidatorFn = ( control : AbstractControl ) : ValidationErrors | null => {
262+ const REGEXP = / ^ [ 0 - 9 a - f A - F ] { 6 } $ / ;
263+ if ( ! control . value ) {
264+ return { error : true } ;
265+ } else if ( ! REGEXP . test ( control . value ) ) {
266+ return { error : true } ;
267+ }
268+ return null ;
269+ } ;
0 commit comments