Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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));
}
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);
}
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();
});
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;
}
{'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('')
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' }
);
}
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));
});
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);
});
}
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);