fromJson static method
FormComponent<DataEntity>
fromJson(
- dynamic json,
- List<
GridField> fields, { - List<
FormFieldProperties> additionalProperties = const [],
Mapping to a concrete implementation based on json
and schema
Throws an ArgumentError if not matching implementation is found.
Implementation
static FormComponent fromJson(
dynamic json,
List<GridField> fields, {
List<FormFieldProperties> additionalProperties = const [],
}) {
final id = json['fieldId'];
final property = json['property'];
final field = fields.firstWhere(
(e) => e.id == id,
orElse: () => throw Exception('Field with id $id not found'),
);
final options = FormComponentOptions.fromJson(json['options']);
final required = json['required'] ?? false;
final data = DataEntity.fromJson(json: json['value'], field: field);
if (field.type == DataType.text &&
options.multi == false &&
data.value?.contains('\n') == true) {
data.value = data.value?.replaceAll('\n', ' ');
}
final type = json['type'];
return FormComponent(
property: property,
data: data,
options: options,
required: required,
field: field,
type: type,
enabled: additionalProperties
.firstWhereOrNull((e) => e.fieldId == id)
?.disabled !=
true,
);
}