Defining relationship form fields
When creating a form, there is a default behaviour for every type of form field relationship:
Attributeform field -ExtendedFormControlwill be createdBelongsToform field -ExtendedFormControlwill be createdHasManyform field - An emptyExtendedFormArraywill be created
For example, for User model:
import { Attribute, HasMany } from 'ngx-form-object';
class User {
@Attribute()
name: string;
@BelongsTo()
address: Address;
@HasMany()
cars: Array<Car>;
}
By default form will be created with:
nameform field asExtendedFormControladdressform field asExtendedFormControlcarsform field asExtendedFormArraycontaining oneExtendedFormControlfor everyCarmodel.
If default form fields don't provide enough control (e.g. you are manipulating multiple levels of relationships on the same page/form), default behaviour can be overriden by implementing one of the following methods:
Create relationship form fields using @BuildRelationshipFormObject decorator
If defined, method decorated with @BuildRelationshipFormObject decorator will be used when creating a form field for any model relationship decorated with @BelongsTo or @HasMany decorators.
This method must return a FormObject instance. Find out more.
Create form fields using BuildControl decorator
If defined, method decorated with BuildControl decorator will be used when building a form field for any model property or relationship decorated with Attribute, BelongsTo or HasMany.
This method must return an instance of ExtendedFormControl, ExtendedFormArray or FormStore. It receives property value as its argument. Find out more.