File

core/forms/humanize-validation-message.pipe.ts

Description

This pipe is responsible for transforming validation error key to actual translatable that are defined in ValidationPattern class.

Example :
<c8y-message>
 {{ 'minLength' | humanizeValidationMessage }}
</c8y-message>

Above code renders corresponding validation message for minLength: "Should have at least {{ requiredLength }} characters"

It is possible to chain translate pipe:

Example :
const errorData = { requiredLength: 5, actualLength: 1};
Example :
<div>
 {{ 'minLength' | humanizeValidationMessage | translate: errorData  }}
</div>

should render: "Should have at least 5 characters"

It is also possible to provide custom translation message. For example:

Example :
const errorData = { requiredLength: 5, actualLength: 1 };
const customMessages = {
  minLength: gettext("File name should have at least {{ requiredLength }} characters")
};
Example :
<div>
 {{ 'minLength' | humanizeValidationMessage:customMessages | translate: errorData }}
</div>

should render: "File name should have at least 5 characters"

Metadata

Methods

transform
transform(errorName: string, customMessages: literal type)
Parameters :
Name Type Optional Default value
errorName string No
customMessages literal type No {}
Returns : string

results matching ""

    No results matching ""