How to use the @angular/forms.FormGroup function in @angular/forms

To help you get started, we’ve selected a few @angular/forms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DBCG / Dataphor / Dataphor / Frontend.Client.Angular / dataphor-frontend-client / src / app / d4 / frontend / source / source.component.ts View on Github external
ngOnInit() {
        this.formGroup = this._form.addSource(this.name, new FormGroup({}));

        let decodedSource = this._utilityService.decodeInline(this.expression);

        let decodedQuery = 'select ' + decodedSource;
        this._apiService
            .post({ value: decodedQuery })
            .then(response => {
                //let handledResponse = this._apiService.handleResponse(response);
                console.log(response);
                if (Array.isArray(response)) {
                    // Return first value from array of objects
                    this._form.updateGroup(this.name, this.formGroup, this._utilityService.getValueFromSourceValue(response[0]));
                }
                else {
                    this._form.updateGroup(this.name, this.formGroup, this._utilityService.getValueFromSourceValue(response));
                }
github Azure / BatchExplorer / src / app / components / gallery / submit / submit-ncj-template.component.ts View on Github external
if (template.parameters[key].defaultValue === "") {
                    validator = null;
                }
            }

            templateFormGroup[key] = new FormControl(defaultValue, validator);
            if (template.parameters[key].metadata && template.parameters[key].metadata.advancedType) {
                // Store the advanced data type as we need it for change events from file-groups
                this._parameterTypeMap[key] = template.parameters[key].metadata.advancedType;
            }

            // Wire up a control change event handler
            this._handleControlChangeEvents(templateFormGroup, key);
        }

        return new FormGroup(templateFormGroup);
    }
github intershop / intershop-pwa / src / app / models / customer / customer.factory.spec.ts View on Github external
describe('fromValue', () => {
    const regForm = new FormGroup({
      birthday: new FormControl(''),
    });
    const addressForm = new FormGroup({
      countryCode: new FormControl('DE'),
      firstName: new FormControl('John'),
      lastName: new FormControl('Doe'),
      addressLine1: new FormControl(''),
      addressLine2: new FormControl(''),
      postalCode: new FormControl(''),
      phoneHome: new FormControl('1234567890'),
      city: new FormControl('')
    });

    regForm.addControl('address', addressForm);

    it(`should return customer data when getting a customer (registration) form value`, () => {
      expect(CustomerFactory.fromValue(regForm.value)).toBeTruthy();
    });
github hsbalar / ngx-recursive-form / projects / ngx-recursive-form / src / lib / ngx-recursive-form.service.ts View on Github external
toFormGroup(formModel): any {
    let formGroup = {};
    let formControls = [];
    formModel.forEach(field => {
      if (field.type == 'object' || field.type == 'array')
      formGroup[field.name] = this.toFormGroupFromArr(field.parameters);
      else if (field.type == 'checkbox')
      formGroup[field.name] = this.toFormGroupFromArr(field.options);
      else
      formControls.push({ name: field.name, control: this.appendFieldFormControlToObject(field)[field.name] });
    });
    let form = new FormGroup(formGroup);
    formControls.forEach(f => form.addControl(f.name, f.control));
    return form;
  }
github toni-moreno / resistor / src / app / common / table-available-actions.ts View on Github external
{'type' : 'selector', 'action' : 'ChangeProperty', 'options' : [
          {'title' : 'Active', 'type':'boolean', 'options' : [
            'true','false']
          },
          {'title': 'InfluxFilter','type':'input', 'options':
            new FormGroup({
              formControl : new FormControl('')
            })
          },
          {'title': 'AlertNotify','type':'input', 'options':
            new FormGroup({
              formControl : new FormControl('', ValidationService.uintegerValidator)
            })
          },
          {'title': 'GrafanaServer','type':'input', 'options':
            new FormGroup({
              formControl : new FormControl('')
            })
          },
          {'title': 'GrafanaDashLabel','type':'input', 'options':
            new FormGroup({
              formControl : new FormControl('')
            })
          },
          {'title': 'GrafanaDashPanelID','type':'input', 'options':
            new FormGroup({
              formControl : new FormControl('')
            })
          },
          {'title': 'ExtraLabel','type':'input', 'options':
            new FormGroup({
              formControl : new FormControl('')
github fiyazbinhasan / AngularSpaCore / AspNetCoreAngularSpa / ClientApp / src / app / forecast / forecast-detail / forecast-detail.component.ts View on Github external
ngOnChanges(): void {
    this.forecastForm = new FormGroup(
      {
        dateFormatted: new FormControl(this.forecast.dateFormatted, {
          validators: Validators.required,
          asyncValidators: [
            this.forecastValidators.existingDateValidator(
              this.forecast.dateFormatted
            )
          ]
        }),
        temperatureC: new FormControl(this.forecast.temperatureC),
        temperatureF: new FormControl(this.forecast.temperatureF),
        summary: new FormControl(this.forecast.summary)
      },
      { updateOn: 'submit' }
    );
  }
github intershop / intershop-pwa / src / app / shared / product / components / product-quantity / product-quantity.component.spec.ts View on Github external
beforeEach(() => {
    fixture = TestBed.createComponent(ProductQuantityComponent);
    component = fixture.componentInstance;
    translate = TestBed.get(TranslateService);
    translate.setDefaultLang('en');
    translate.use('en');
    product = { sku: 'sku' } as Product;
    product.inStock = true;
    product.minOrderQuantity = 1;
    product.availability = true;
    element = fixture.nativeElement;
    component.product = product;
    component.controlName = 'quantity';
    component.parentForm = new FormGroup({});
    component.parentForm.addControl(component.controlName, new FormControl(1));
  });
github Okty-io / okty / src / app / modules / learning / components / actions / qcm / qcm.component.ts View on Github external
this.action.config.questions.map((question, indexQuestion) => {
            const group = new FormGroup({});

            question.questions.map((label, indexLabel) => {
                let id = (indexLabel + 1).toString();
                if (question.responses.length <= 1) {
                    id = '0';
                }

                group.addControl(id, new FormControl(false));
            });

            this.form.addControl(indexQuestion.toString(), group);
        });
    }
github Squidex / squidex / src / Squidex / app / shared / state / contents.forms.ts View on Github external
private addArrayItem(partitionForm: FormArray, field: RootFieldDto, partition: Partition, source?: FormGroup) {
        const itemForm = new FormGroup({});

        for (const nestedField of field.nested) {
            if (nestedField.properties.isContentField) {
                let value = FieldDefaultValue.get(nestedField);

                if (source) {
                    const sourceField = source.get(nestedField.name);

                    if (sourceField) {
                        value = sourceField.value;
                    }
                }

                const nestedValidators = FieldsValidators.create(nestedField, partition.isOptional);
                const nestedForm = new FormControl(value, nestedValidators);