File

src/reactive-form/form-field.model.ts

Constructor

constructor(values: IFormField)

Methods

required
required()
Returns: FormField
setValidators
setValidators(v: ValidatorFn | ValidatorFn[])
Returns: FormField
setValue
setValue(v: any)
Returns: FormField
addValidator
addValidator(v: ValidatorFn)
Returns: FormField

Properties

col
col: string
control
control: FormControl
firstValue
firstValue: any
id
id: string
label
label: string
more
more: any
options
options: any
optionText
optionText: string
optionValue
optionValue: string
type
type: string
import { FormControl, ValidatorFn, Validators } from '@angular/forms';

declare var Object: any

export interface IFormField {
    id: string
    type: string
    label: string
    col: string

    /*For selects*/
    options: any
    optionValue: string
    optionText: string
    firstValue: any

    more: any

}

export class FormField implements IFormField {

    id: string
    type: string
    label: string
    options: any
    optionValue: string
    optionText: string
    col: string
    firstValue: any
    more: any

    control: FormControl

    constructor(values: IFormField) {
        Object.assign(this, values);
        this.control = new FormControl('')
    }

    required(): FormField {
        this.control.setValidators(<any>Validators.required)
        return this
    }

    setValidators(v: ValidatorFn | ValidatorFn[]): FormField {
        this.control.setValidators(v)
        return this
    }

    setValue(v: any): FormField {
        this.control.setValue(v)
        return this
    }

    addValidator(v: ValidatorFn): FormField {
        let validators: any[] = []
        if (this.control.validator)
            validators.push(this.control.validator)

        validators.push(v)
        this.control.setValidators(validators)
        return this
    }


}

results matching ""

    No results matching ""