angular-forms

Expected validator to return Promise or Observable

放肆的年华 提交于 2020-03-17 04:25:46
问题 Im trying to do a custom validation on Angular 5 but I'm facing the following error Expected validator to return Promise or Observable I just want to return an error to the form if the value doesnt match the required, heres my code: This is the component where is my form constructor(fb: FormBuilder, private cadastroService:CadastroService) { this.signUp = fb.group({ "name": ["", Validators.compose([Validators.required, Validators.minLength(2)])], "email": ["", Validators.compose([Validators

How to add custom validator to a FormArray?

喜夏-厌秋 提交于 2020-03-05 02:59:40
问题 I want to add custom validator to form in order to prevent mat-step switching to next step. All works well when I use FormGroups but I fail to achieve validation when I have to use FormArray. I've tried at least two variants of assigning validator on form initialization: inside array statuses: this._formBuilder.array([this.createStatus()], defaultStatusValidator()) inside parent form of array this.productionLineStatuses = this._formBuilder.group({statuses: this._formBuilder.array([this

How to add custom validator to a FormArray?

谁说我不能喝 提交于 2020-03-05 02:57:47
问题 I want to add custom validator to form in order to prevent mat-step switching to next step. All works well when I use FormGroups but I fail to achieve validation when I have to use FormArray. I've tried at least two variants of assigning validator on form initialization: inside array statuses: this._formBuilder.array([this.createStatus()], defaultStatusValidator()) inside parent form of array this.productionLineStatuses = this._formBuilder.group({statuses: this._formBuilder.array([this

Readonly/Disabled input not submitting in Angular

情到浓时终转凉″ 提交于 2020-02-29 06:10:29
问题 I've been having problems creating a form in Angular 2. I need to submit some values that are dinamically generated by a service. Using the http module of Angular I get a price and then the user can now exactly how much bitcoin is an X amount of chilean pesos. What I'm trying to do is submit all that data. I can't do it because angular forms are not submitting the disabled/readonly inputs. These inputs are the exchange rate and the target amount (equivalent in btc). I tried the template

Readonly/Disabled input not submitting in Angular

二次信任 提交于 2020-02-29 06:10:19
问题 I've been having problems creating a form in Angular 2. I need to submit some values that are dinamically generated by a service. Using the http module of Angular I get a price and then the user can now exactly how much bitcoin is an X amount of chilean pesos. What I'm trying to do is submit all that data. I can't do it because angular forms are not submitting the disabled/readonly inputs. These inputs are the exchange rate and the target amount (equivalent in btc). I tried the template

Disable Angular 5 Input fields correct way

左心房为你撑大大i 提交于 2020-02-21 08:10:24
问题 I have a FormGroup that was created like that: form: FormGroup; constructor(private _formBuilder: FormBuilder) { } this.form = this._formBuilder.group({ name: ['', Validators.required], email: ['', Validators.required, Validators.email] }); When an event occurs I want to disable those inputs, so, in the HTML I added: <input class="form-control" placeholder="Name" name="name" formControlName="name" [(ngModel)]="name" autocomplete="off" [disabled]="isDisabled" required> <input class="form

Disable Angular 5 Input fields correct way

混江龙づ霸主 提交于 2020-02-21 08:09:09
问题 I have a FormGroup that was created like that: form: FormGroup; constructor(private _formBuilder: FormBuilder) { } this.form = this._formBuilder.group({ name: ['', Validators.required], email: ['', Validators.required, Validators.email] }); When an event occurs I want to disable those inputs, so, in the HTML I added: <input class="form-control" placeholder="Name" name="name" formControlName="name" [(ngModel)]="name" autocomplete="off" [disabled]="isDisabled" required> <input class="form

How disable all the dates before a particular date in angular?

烂漫一生 提交于 2020-02-20 08:11:06
问题 I am building a component (html, css, spec.ts, ts) in angular in which I always want endDate > startDate. I have followed this link https://material.angular.io/components/datepicker/overview in order make multiple datepickers. Below is my HTML for startDate and endDate : startDate: <div class="start-date" fxFlex="50%" fxFlexOrder="1"> <mat-form-field> <input matInput [matDatepicker]="picker1" placeholder="{{'PORTAL.STARTDATE' | translate}}" type="text" formControlName="startDate" [(ngModel)]=

How disable all the dates before a particular date in angular?

孤街浪徒 提交于 2020-02-20 08:11:01
问题 I am building a component (html, css, spec.ts, ts) in angular in which I always want endDate > startDate. I have followed this link https://material.angular.io/components/datepicker/overview in order make multiple datepickers. Below is my HTML for startDate and endDate : startDate: <div class="start-date" fxFlex="50%" fxFlexOrder="1"> <mat-form-field> <input matInput [matDatepicker]="picker1" placeholder="{{'PORTAL.STARTDATE' | translate}}" type="text" formControlName="startDate" [(ngModel)]=

Binding FormControl validators to a custom form Material Select component

荒凉一梦 提交于 2020-02-06 08:01:09
问题 I have this stackblitz set up by way of an example. I have a standard input form field and a custom field that shows a select bound to an array. <form [formGroup]="formGroup"> <mat-form-field class="field"> <mat-label>City</mat-label> <input matInput placeholder="City" formControlName="address1" /> </mat-form-field> <app-dataset-select label="Country" [items]="countries" formControlName="countryId"></app-dataset-select> </form> The whole thing is wrapped by a form with validation: this