diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-29 15:33:24 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-01-03 14:20:52 +0100 |
commit | cc4bf76c13e38e9065d49161b6e0485657424577 (patch) | |
tree | d7ecc6bd58037c41587eb911776b676592985cd1 /client/src/app/+videos/+video-edit/shared/video-edit.component.ts | |
parent | e2aeb8ad0f3055d54ac416ec5908d26b70aac4be (diff) | |
download | PeerTube-cc4bf76c13e38e9065d49161b6e0485657424577.tar.gz PeerTube-cc4bf76c13e38e9065d49161b6e0485657424577.tar.zst PeerTube-cc4bf76c13e38e9065d49161b6e0485657424577.zip |
Handle async validators
Diffstat (limited to 'client/src/app/+videos/+video-edit/shared/video-edit.component.ts')
-rw-r--r-- | client/src/app/+videos/+video-edit/shared/video-edit.component.ts | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/client/src/app/+videos/+video-edit/shared/video-edit.component.ts b/client/src/app/+videos/+video-edit/shared/video-edit.component.ts index 8ce36121d..be3bbe9be 100644 --- a/client/src/app/+videos/+video-edit/shared/video-edit.component.ts +++ b/client/src/app/+videos/+video-edit/shared/video-edit.component.ts | |||
@@ -2,7 +2,7 @@ import { forkJoin } from 'rxjs' | |||
2 | import { map } from 'rxjs/operators' | 2 | import { map } from 'rxjs/operators' |
3 | import { SelectChannelItem } from 'src/types/select-options-item.model' | 3 | import { SelectChannelItem } from 'src/types/select-options-item.model' |
4 | import { ChangeDetectorRef, Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' | 4 | import { ChangeDetectorRef, Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' |
5 | import { AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Validators } from '@angular/forms' | 5 | import { AbstractControl, FormArray, FormControl, FormGroup, Validators } from '@angular/forms' |
6 | import { HooksService, PluginService, ServerService } from '@app/core' | 6 | import { HooksService, PluginService, ServerService } from '@app/core' |
7 | import { removeElementFromArray } from '@app/helpers' | 7 | import { removeElementFromArray } from '@app/helpers' |
8 | import { BuildFormValidator } from '@app/shared/form-validators' | 8 | import { BuildFormValidator } from '@app/shared/form-validators' |
@@ -309,10 +309,10 @@ export class VideoEditComponent implements OnInit, OnDestroy { | |||
309 | for (const setting of this.pluginFields) { | 309 | for (const setting of this.pluginFields) { |
310 | await this.pluginService.translateSetting(setting.pluginInfo.plugin.npmName, setting.commonOptions) | 310 | await this.pluginService.translateSetting(setting.pluginInfo.plugin.npmName, setting.commonOptions) |
311 | 311 | ||
312 | const validator = (control: AbstractControl): ValidationErrors | null => { | 312 | const validator = async (control: AbstractControl) => { |
313 | if (!setting.commonOptions.error) return null | 313 | if (!setting.commonOptions.error) return null |
314 | 314 | ||
315 | const error = setting.commonOptions.error({ formValues: this.form.value, value: control.value }) | 315 | const error = await setting.commonOptions.error({ formValues: this.form.value, value: control.value }) |
316 | 316 | ||
317 | return error?.error ? { [setting.commonOptions.name]: error.text } : null | 317 | return error?.error ? { [setting.commonOptions.name]: error.text } : null |
318 | } | 318 | } |
@@ -320,7 +320,8 @@ export class VideoEditComponent implements OnInit, OnDestroy { | |||
320 | const name = setting.commonOptions.name | 320 | const name = setting.commonOptions.name |
321 | 321 | ||
322 | pluginObj[name] = { | 322 | pluginObj[name] = { |
323 | VALIDATORS: [ validator ], | 323 | ASYNC_VALIDATORS: [ validator ], |
324 | VALIDATORS: [], | ||
324 | MESSAGES: {} | 325 | MESSAGES: {} |
325 | } | 326 | } |
326 | 327 | ||
@@ -342,6 +343,9 @@ export class VideoEditComponent implements OnInit, OnDestroy { | |||
342 | 343 | ||
343 | this.cd.detectChanges() | 344 | this.cd.detectChanges() |
344 | this.pluginFieldsAdded.emit() | 345 | this.pluginFieldsAdded.emit() |
346 | |||
347 | // Plugins may need other control values to calculate potential errors | ||
348 | this.form.valueChanges.subscribe(() => this.formValidatorService.updateTreeValidity(this.pluginDataFormGroup)) | ||
345 | } | 349 | } |
346 | 350 | ||
347 | private trackPrivacyChange () { | 351 | private trackPrivacyChange () { |