aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos/+video-edit/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-29 15:33:24 +0100
committerChocobozzz <me@florianbigard.com>2022-01-03 14:20:52 +0100
commitcc4bf76c13e38e9065d49161b6e0485657424577 (patch)
treed7ecc6bd58037c41587eb911776b676592985cd1 /client/src/app/+videos/+video-edit/shared
parente2aeb8ad0f3055d54ac416ec5908d26b70aac4be (diff)
downloadPeerTube-cc4bf76c13e38e9065d49161b6e0485657424577.tar.gz
PeerTube-cc4bf76c13e38e9065d49161b6e0485657424577.tar.zst
PeerTube-cc4bf76c13e38e9065d49161b6e0485657424577.zip
Handle async validators
Diffstat (limited to 'client/src/app/+videos/+video-edit/shared')
-rw-r--r--client/src/app/+videos/+video-edit/shared/video-edit.component.ts12
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'
2import { map } from 'rxjs/operators' 2import { map } from 'rxjs/operators'
3import { SelectChannelItem } from 'src/types/select-options-item.model' 3import { SelectChannelItem } from 'src/types/select-options-item.model'
4import { ChangeDetectorRef, Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' 4import { ChangeDetectorRef, Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'
5import { AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Validators } from '@angular/forms' 5import { AbstractControl, FormArray, FormControl, FormGroup, Validators } from '@angular/forms'
6import { HooksService, PluginService, ServerService } from '@app/core' 6import { HooksService, PluginService, ServerService } from '@app/core'
7import { removeElementFromArray } from '@app/helpers' 7import { removeElementFromArray } from '@app/helpers'
8import { BuildFormValidator } from '@app/shared/form-validators' 8import { 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 () {