File

src/app/tasks/task-launch/task-launch.validator.ts

Description

Validators for Task Launch Form Static methods

Example

Index

Methods

Methods

Static key
key(control: FormControl)

Key should start with app. or deployer. or scheduler if not empty

Parameters :
Name Type Optional Description
control FormControl
Returns : { invalid: boolean; }
Static keyRequired
keyRequired(group: FormGroup)

Key is required if the group is not empty

Parameters :
Name Type Optional Description
group FormGroup
Returns : { invalid: boolean; }
import { FormControl, FormGroup, Validators } from '@angular/forms';

/**
 * Validators for Task Launch Form
 * Static methods
 *
 * @author Damien Vitrac
 */
export class TaskLaunchValidator {

  /**
   * Key is required if the group is not empty
   *
   * @param {FormGroup} group
   * @returns {any}
   */
  static keyRequired(group: FormGroup) {
    const control = new FormControl(null, Validators.required);
    const hasValueSet = group.get('val').value !== '';
    control.setValue(group.get('key').value);
    if (!hasValueSet || (hasValueSet && control.valid)) {
      return null;
    }
    return { invalid: true };
  }

  /**
   * Key should start with app. or deployer. or scheduler if not empty
   *
   * @param {FormControl} control
   * @returns {any}
   */
  static key(control: FormControl) {
    const value = control.value;
    if (value && !value.startsWith('app.') && !value.startsWith('deployer.') && !value.startsWith('scheduler.')) {
      return { invalid: true };
    }
    return null;
  }

}

results matching ""

    No results matching ""