|
|
@ -374,24 +374,33 @@ export class EditContentForm extends Form<FormGroup> { |
|
|
this.findArrayItemForm(field, language).removeAt(index); |
|
|
this.findArrayItemForm(field, language).removeAt(index); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public insertArrayItem(field: RootFieldDto, language: AppLanguageDto, value?: {}) { |
|
|
public insertArrayItem(field: RootFieldDto, language: AppLanguageDto, source?: FormGroup) { |
|
|
if (field.nested.length > 0) { |
|
|
if (field.nested.length > 0) { |
|
|
const formControl = this.findArrayItemForm(field, language); |
|
|
const formControl = this.findArrayItemForm(field, language); |
|
|
|
|
|
|
|
|
this.addArrayItem(field, language, formControl, value); |
|
|
this.addArrayItem(field, language, formControl, source); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private addArrayItem(field: RootFieldDto, language: AppLanguageDto | null, partitionForm: FormArray, value?: {}) { |
|
|
private addArrayItem(field: RootFieldDto, language: AppLanguageDto | null, partitionForm: FormArray, source?: FormGroup) { |
|
|
const itemForm = new FormGroup({}); |
|
|
const itemForm = new FormGroup({}); |
|
|
|
|
|
|
|
|
let isOptional = field.isLocalizable && !!language && language.isOptional; |
|
|
let isOptional = field.isLocalizable && !!language && language.isOptional; |
|
|
|
|
|
|
|
|
for (let nested of field.nested) { |
|
|
for (let nested of field.nested) { |
|
|
const nestedValidators = FieldValidatorsFactory.createValidators(nested, isOptional); |
|
|
const nestedValidators = FieldValidatorsFactory.createValidators(nested, isOptional); |
|
|
const nestedDefault = value ? value[nested.name] : FieldDefaultValue.get(nested); |
|
|
|
|
|
|
|
|
|
|
|
itemForm.setControl(nested.name, new FormControl(nestedDefault, nestedValidators)); |
|
|
let value = FieldDefaultValue.get(nested); |
|
|
|
|
|
|
|
|
|
|
|
if (source) { |
|
|
|
|
|
const sourceField = source.get(nested.name); |
|
|
|
|
|
|
|
|
|
|
|
if (sourceField) { |
|
|
|
|
|
value = sourceField.value; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
itemForm.setControl(nested.name, new FormControl(value, nestedValidators)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
partitionForm.push(itemForm); |
|
|
partitionForm.push(itemForm); |
|
|
|