- Formly V6 now requires Angular Version >= 13
-
All Formly components now use
OnPush
change detection, so in order to let Angular detect changes oftemplateOptions
properties either ensure a default value is set or use spread object assign instead of regular assign:export class CustomFieldType extends FieldType { defaultOptions = { templateOptions: { + loading: false, }, }; showLoader() { field.templateOptions.loading = true } }
showLoader() { - field.templateOptions.loading = true + field.templateOptions = { + ...field.templateOptions, + loading: true + }; }
-
Note: The above changes concern only the extra properties defined in your custom type and not the provided ones from Formly such as
disabled
,label
...// still working in `V6` field.templateOptions.disabled = true;
-
-
The defaultValue for fieldGroup and fieldArray has been changed to
undefined
instead of empty object. If you want to rely on the old behavior set thedefaultValue
:before:
If no default value is set thedefaultValue
for formlyGroup is{}
and for fieldArray[]
after:
FormlyModule.forRoot({ types: [ { extends: 'formly-group', defaultOptions: { defaultValue: {} } } ], })
-
The initial value of the created FormControl has been changed from
null
toundefined
to match the field model value.before:
let fields: FormlyFieldConfig[] = [ { key: 'text', type: 'input' } ]
after:
let fields: FormlyFieldConfig[] = [ { key: 'text', type: 'input', defaultValue: null } ]
-
The
checkExpressionOn
option is set tomodelChange
by default, which improve performance. To rely on the old behavior you need to passchangeDetectionCheck
tocheckExpressionOn
:FormlyModule.forRoot({ + extras: { + checkExpressionOn: 'changeDetectionCheck', + }, }),
-
The
lazyRender
option is enabled by default, which remove the hidden fields from the DOM instead of using CSS to control their visibility. To rely on the old behavior you need to passfalse
tolazyRender
:FormlyModule.forRoot({ + extras: { + lazyRender: false, + }, }),
-
The
resetFieldOnHide
option is enabled by default, which remove the field value from the model on hide.To disable this feature for a specific field use
resetOnHide
:let fields: FormlyFieldConfig[] = [ { key: 'text', type: 'input', + resetOnHide: false } ]
To use the the old behavior pass
false
toresetFieldOnHide
:FormlyModule.forRoot({ + extras: { + resetFieldOnHide: false, + }, }),
-
Add support of strict template checking:
In case
strictTemplates
is enabled after the upgrade, addFieldTypeConfig
to all custom field type that use[formControl]
input which expect theformControl
property to be an instance ofFormControl
.- import { FieldType } from '@ngx-formly/core'; + import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; @Component({ template: `<input [formControl]="formControl" />`, }) - export class CustomFieldType extends FieldType {} + export class CustomFieldType extends FieldType<FieldTypeConfig> {}
-
The message validation key:
maxlength
andmaxlength
has been changed from lowercase into snakecase format in order to match the same key oftemplateOptions.minLength
andtemplateOptions.maxLength
:- NgModule declaration:
FormlyModule.forRoot({ validationMessages: [ - { name: 'minlength', message: minlengthValidationMessage }, + { name: 'minLength', message: minLengthValidationMessage }, - { name: 'maxlength', message: maxlengthValidationMessage }, + { name: 'maxLength', message: maxLengthValidationMessage }, ], })
- Field Config declaration (if using
validation.messages
):
fields: FormlyFieldConfig[] = [ { key: 'password', type: 'input', templateOptions: { label: 'Password', minLength: 6, maxLength: 20, }, validation: { messages: { - minLength: 'minLength custom message', + minLength: 'minLength custom message', - maxLength: 'maxLength custom message', + maxLength: 'maxLength custom message', }, }, },
- Reset form value: In case you rely on
form.reset()
instead ofoptions.resetModel()
, please note that if you callreset
without an explicit value, its value reverts to its default value instead ofnull
.
- In case you use the extra option
map
to customize the generated field, you need to make change to take account of following properties:fieldArray
which returnfunction
instead of an object.templateOptions
which has been replaced byprops
.hideExpression
which has been replaced byexpressions: { hide: ... }
.expressionProperties
which has been replaced byexpressions
.
this.formlyJsonschema.toFieldConfig(schema, {
map: (field: FormlyFieldConfig, schema: JSONSchema7) => {
... // update `fieldArray` value
return field;
},
});
- The
null
validation message has been removed and replaced bytype
validation message:
+ export function typeValidationMessage({ schemaType }) {
+ return `should be "${schemaType[0]}".`;
+ }
@NgModule({
imports: [
FormlyModule.forRoot({
validationMessages: [
- { name: 'null', message: 'should be null' },
+ { name: 'type', message: typeValidationMessage },
],
}),
],
})
export class AppModule {}
-
Bootstrap v4 support is removed and replaced with v5 support. To upgrade check the migration documentation https://getbootstrap.com/docs/5.0/migration/
-
formCheck
:custom
prefix has been removed and replaced by the following values:Before After custom default custom-inline inline custom-switch switch -
add-on: The two first argument of
onClick
handler has been replaced byfield
instance.- onClick: (to, fieldType, $event) => ..., + onClick: (field, $event) => ...,
-
The library now require the Ionic V6, To upgrade your Ionic 5 apps to Ionic 6 check Ionic guide
-
datetime
: due to the breaking changes introduced inion-datetime
component as described here https://ionicframework.com/docs/intro/upgrading-to-ionic-6#datetime, the following properies:pickerOptions
,pickerFormat
,monthNames
,monthShortNames
,dayNames
anddayShortNames
has been removed.To customize
datetime
presentation and format, use the following properties:property default presentation date
https://ionicframework.com/docs/api/datetime#presentation locale default
https://ionicframework.com/docs/api/datetime#locale displayFormat null
use the Date pipe format