I want to create a simple form with validations, and I want to translate all error messages into Spanish. It works fine for 'required', 'min' and 'max' validators, but when I do the same with 'minLength' and 'maxLength', no error message shows.
It is weird because the fields are still marked as incorrect (they appear in red), but no error message appears. The message formatting functions are just not called.
Here is the essential part of my code:
form = new FormGroup({});
model = { email: 'email@gmail.com' };
validation = {
messages: {
required: (error, field: FormlyFieldConfig) => `Este campo es obligatorio.`,
min: (error, field: FormlyFieldConfig) => `El valor debe ser mayor o igual que ${error.min}.`,
max: (error, field: FormlyFieldConfig) => `El valor debe ser menor o igual que ${error.max}.`,
minLength: (error, field: FormlyFieldConfig) => `La longitud mínima es ${error.minLength}.`,
maxLength: (error, field: FormlyFieldConfig) => `La longitud máxima es ${error.maxLength}.`
}
};
fields: FormlyFieldConfig[] = [ {
fieldGroupClassName: 'row',
fieldGroup: [
{
key: 'reference',
type: 'input',
className: 'col-xs-6',
templateOptions: {
label: 'Referencia',
type: 'string',
required: true,
minLength: 3,
maxLength: 30,
},
validation: this.validation
} ]
}];