ManyRelatedViewModelField
SourceDefine a field that contains multiple records from another ViewModel
This behaves the same as RelatedViewModelField but sourceFieldName
must refer to a ListField and all values are an array instead of a single value.
API
Constructor
new ManyRelatedViewModelField(props)
SourceParameter | Type | Description | |
---|---|---|---|
props.asyncChoices | AsyncChoicesInterface | Asynchronous choices for this field. Only one of | |
props.blank | boolean | Is this field allowed to be assigned a blank (null, undefined, "") value? Defaults to false | |
props.blankAsNull | boolean | Frontend values are often stored as strings even if they are not stored like that
in a backend (eg. database). Depending on your backend implementation it may expect
empty values to be represented as | |
props.choices | Map|[SingleValueT, string][] | Choices for this field. Should be a mapping of value to the label for the choice. | |
props.defaultValue | BaseRelatedViewModelValueType|null| Function | Default value for this field. This can either be a function that returns a value or the value directly. | |
props.helpText | string | Optional help text for this field that might be shown on a form | |
props.label | string | Label for this field. If not specified will be generated from the name. | |
props.readOnly | boolean | True if field should be considered read only (eg. excluded from forms) | |
props.writeOnly | boolean | True if field should be considered write only (eg. excluded from detail views) | |
props.cache | ViewModelCache | The cache to use to retrieve related records from. Uses the default model cache if not specified. | |
* | props.sourceFieldName | SourceFieldNameT | The name of the field on the ViewModel that stores the ID for this relation |
* | props.to | Function |ViewModel Class |
Methods
toJS(value)
SourceConverts the linked record to a plain javascript object
Parameter | Type | Description | |
---|---|---|---|
* | value | RelatedViewModelValueType[] |
Static Properties
fieldClassName: string
Inherited Methods
format(value)
SourceFormat the value for displaying in a form widget. eg. This could convert a Date
into
a localized date string
Parameter | Type | Description | |
---|---|---|---|
* | value | RelatedViewModelValueType[] |
isEqual(value1,value2)
SourceCompares to relations for equality - if the ViewModel has the same data this returns true
Parameter | Type | Description | |
---|---|---|---|
* | value1 | RelatedViewModelValueType[] | |
* | value2 | RelatedViewModelValueType[] |
parse(value)
SourceParse a value received from a form widget onChange
call. eg. This could convert a localized date string
into a Date
.
Parameter | Type | Description | |
---|---|---|---|
* | value | FieldDataMappingRaw[]|null |
One of the following:
RelatedViewModelValueType[]OR
nullresolveViewModel()
SourceResolves the ViewModel this field links to. This is necessary as the ViewModel might be a dynamic import that hasn't yet loaded.
This needs to be called manually before to
can be accessed.
toString()
SourceInherited Properties
_isResolvingDeps: boolean
asyncChoices: AsyncChoicesInterface
Async choices for this field.
blank: boolean
Is this field required when saving a record?
blankAsNull: boolean
If true an empty string value should be converted to a null value
boundRecord: ViewModelInterface
When accessed on a bound field will return the current instance of the ViewModel the field is bound to.
If called on an unbound field then this will always be undefined and a warning will be raised.
cache: ViewModelCache
choices: Map
defaultValue: Promise<RelatedViewModelValueType[]|null|undefined>|RelatedViewModelValueType[]|null|undefined
Get the default value for this field.
helpText: string
Help text that can be displayed with the form widget
isBound: boolean
Returns true if field is bound to a ViewModel instance. When a field is bound to a instance the value for that field is accessible on the 'value' property.
label: string
Label that can be displayed as the form label for a widget
If not specified will be generated from name
.
many: boolean
model: ViewModel Class
The ViewModel class this field is attached to.
This will throw an error if the field is not attached to a model.
name: string
The name of this field.
This will throw an error if the field is not attached to a model.
readOnly: boolean
Indicates this field should only be read, not written. Not enforced but can be used by components to adjust their output accordingly (eg. exclude it from a form or show it on a form with a read only input)
sourceField: Field
sourceFieldName: SourceFieldNameT
to: ViewModel Class
Get the ViewModel this related field is to.
If to
was defined as a function returning a Promise
then you must call resolveViewModel
and wait for the returned Promise
to resolve before accessing this otherwise an error will be thrown
value: RelatedViewModelValueType[]
When isBound
is true this will return the current value of this field on the bound ViewModel.
Otherwise will always be undefined.
writeOnly: boolean
Indicates this field should only be written only and is not intended to be read directly. This is not enforced but can be used by components to adjust their output accordingly (eg. exclude it from a detail view on a record)