Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ pattern: /[A-Z]/,
},
validation: {
messages: {
required: (err, field) => $localize `:@@CUSTOM_VALIDATION_MESSAGE_TRANSLATION_ID:CUSTOM_VALIDATION_MESSAGE`,
maxlength: (err, field) => $localize `:@@CUSTOM_VALIDATION_MESSAGE_TRANSLATION_ID:CUSTOM_VALIDATION_MESSAGE`
required: (_err, field) => $localize `:@@CUSTOM_VALIDATION_MESSAGE_TRANSLATION_ID:CUSTOM_VALIDATION_MESSAGE`,
maxlength: (_err, field) => $localize `:@@CUSTOM_VALIDATION_MESSAGE_TRANSLATION_ID:CUSTOM_VALIDATION_MESSAGE`
}
},
asyncValidators: { validation: [ 'uniqueName', 'isEnsured' ] },
Expand Down Expand Up @@ -266,8 +266,8 @@ max: 100,
},
validation: {
messages: {
min: (err, field) => $localize `:@@test.mock-edit.amount.min:CUSTOM_VALIDATION_MESSAGE`,
max: (err, field) => $localize `:@@test.mock-edit.amount.max:CUSTOM_VALIDATION_MESSAGE`
min: (_err, field) => $localize `:@@test.mock-edit.amount.min:CUSTOM_VALIDATION_MESSAGE`,
max: (_err, field) => $localize `:@@test.mock-edit.amount.max:CUSTOM_VALIDATION_MESSAGE`
}
},
},
Expand Down Expand Up @@ -659,7 +659,7 @@ maxLength: 50,
},
validation: {
messages: {
pattern: (err, field) => $localize `:@@test.mock-edit.email1.pattern:CUSTOM_VALIDATION_MESSAGE`
pattern: (_err, field) => $localize `:@@test.mock-edit.email1.pattern:CUSTOM_VALIDATION_MESSAGE`
}
},
},
Expand Down Expand Up @@ -688,7 +688,7 @@ maxLength: 50,
},
validation: {
messages: {
pattern: (err, field) => $localize `:@@validators.pattern.emailAddress:Invalid email address format`
pattern: (_err, field) => $localize `:@@validators.pattern.emailAddress:Invalid email address format`
}
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import { CustomValidatorsService, customValidatorsFactory } from 'src/app/shared
FormlyModule.forChild(
{
validationMessages: [
{ name: 'maxlength', message: (err, field) => $localize `:@@validators.maxLength:${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters` },
{ name: 'pattern', message: (err, field) => $localize `:@@validators.pattern:${field?.templateOptions?.label}:property-name: is not in valid format` },
{ name: 'max', message: (err, field) => $localize `:@@validators.max:${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:` },
{ name: 'required', message: (err, field) => $localize `:@@validators.required:${field?.templateOptions?.label}:property-name: is required` }
{ name: 'maxlength', message: (_err, field) => $localize `:@@validators.maxLength:${field?.props?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters` },
{ name: 'pattern', message: (_err, field) => $localize `:@@validators.pattern:${field?.props?.label}:property-name: is not in valid format` },
{ name: 'max', message: (_err, field) => $localize `:@@validators.max:${field?.props?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:` },
{ name: 'required', message: (_err, field) => $localize `:@@validators.required:${field?.props?.label}:property-name: is required` }
]
}
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,24 @@ public string AddAsyncValidators(string propertyName)
}

[TestCase(nameof(FormMock.Name), ExpectedResult =
"required: (err, field) => $localize `:@@CUSTOM_VALIDATION_MESSAGE_TRANSLATION_ID:CUSTOM_VALIDATION_MESSAGE`," +
"maxLength: (err, field) => $localize `:@@CUSTOM_VALIDATION_MESSAGE_TRANSLATION_ID:CUSTOM_VALIDATION_MESSAGE`")]
"required: (_err, field) => $localize `:@@CUSTOM_VALIDATION_MESSAGE_TRANSLATION_ID:CUSTOM_VALIDATION_MESSAGE`," +
"maxLength: (_err, field) => $localize `:@@CUSTOM_VALIDATION_MESSAGE_TRANSLATION_ID:CUSTOM_VALIDATION_MESSAGE`")]
[TestCase(nameof(FormMock.Amount), ExpectedResult =
"min: (err, field) => $localize `:@@test.mock-edit.amount.min:CUSTOM_VALIDATION_MESSAGE`," +
"max: (err, field) => $localize `:@@test.mock-edit.amount.max:CUSTOM_VALIDATION_MESSAGE`")]
[TestCase(nameof(FormMock.Email1), ExpectedResult = "pattern: (err, field) => $localize `:@@test.mock-edit.email1.pattern:CUSTOM_VALIDATION_MESSAGE`")]
[TestCase(nameof(FormMock.Email2), ExpectedResult = "pattern: (err, field) => $localize `:@@validators.pattern.emailAddress:Invalid email address format`")]
"min: (_err, field) => $localize `:@@test.mock-edit.amount.min:CUSTOM_VALIDATION_MESSAGE`," +
"max: (_err, field) => $localize `:@@test.mock-edit.amount.max:CUSTOM_VALIDATION_MESSAGE`")]
[TestCase(nameof(FormMock.Email1), ExpectedResult = "pattern: (_err, field) => $localize `:@@test.mock-edit.email1.pattern:CUSTOM_VALIDATION_MESSAGE`")]
[TestCase(nameof(FormMock.Email2), ExpectedResult = "pattern: (_err, field) => $localize `:@@validators.pattern.emailAddress:Invalid email address format`")]
public string AddCustomValidationMessages(string propertyName)
{
var formControl = _formComponent.FormControlsOfType<FormControl>().Single(x => x.PropertyName == propertyName.Camelize());
return _htmlHelper.AddCustomValidationMessages(formControl, true)?.ToString()?.Replace("\r\n", "") ?? "";
}

[TestCase(ExpectedResult =
"{ name: 'maxLength', message: (err, field) => $localize `:@@validators.maxLength:${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters` }," +
"{ name: 'pattern', message: (err, field) => $localize `:@@validators.pattern:${field?.templateOptions?.label}:property-name: is not in valid format` }," +
"{ name: 'max', message: (err, field) => $localize `:@@validators.max:${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:` }," +
"{ name: 'required', message: (err, field) => $localize `:@@validators.required:${field?.templateOptions?.label}:property-name: is required` }")]
"{ name: 'maxLength', message: (_err, field) => $localize `:@@validators.maxLength:${field?.props?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters` }," +
"{ name: 'pattern', message: (_err, field) => $localize `:@@validators.pattern:${field?.props?.label}:property-name: is not in valid format` }," +
"{ name: 'max', message: (_err, field) => $localize `:@@validators.max:${field?.props?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:` }," +
"{ name: 'required', message: (_err, field) => $localize `:@@validators.required:${field?.props?.label}:property-name: is required` }")]
public string AddCommonValidationMessages() =>
_htmlHelper.AddCommonValidationMessages(_featureModule, true)?.ToString()?.Replace("\r\n", "") ?? "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void IsRequired()
_validationConfiguration.ValidationRules.Single().FormlyTemplateOptions
.Should().BeEquivalentTo("required: true");
_validationConfiguration.ValidationRules.Single().FormlyValidationMessage
.Should().Be("${field?.templateOptions?.label}:property-name: is required");
.Should().Be("${field?.props?.label}:property-name: is required");
}

[Test]
Expand All @@ -61,7 +61,7 @@ public void Match()
_validationConfiguration.ValidationRules.Single().FormlyTemplateOptions
.Should().BeEquivalentTo("pattern: /^[A-Z]{4}[1-9]{8}$/mu");
_validationConfiguration.ValidationRules.Single().FormlyValidationMessage
.Should().Be("${field?.templateOptions?.label}:property-name: is not in valid format");
.Should().Be("${field?.props?.label}:property-name: is not in valid format");
}

[Test]
Expand Down Expand Up @@ -103,7 +103,7 @@ public void MinLength()
_validationConfiguration.ValidationRules.Single().FormlyTemplateOptions
.Should().BeEquivalentTo("minLength: 0");
_validationConfiguration.ValidationRules.Single().FormlyValidationMessage
.Should().Be("${field?.templateOptions?.label}:property-name: should have at least ${field?.templateOptions?.minLength}:min-value: characters");
.Should().Be("${field?.props?.label}:property-name: should have at least ${field?.templateOptions?.minLength}:min-value: characters");
}

[Test]
Expand All @@ -124,7 +124,7 @@ public void MaxLength()
_validationConfiguration.ValidationRules.Single().FormlyTemplateOptions
.Should().BeEquivalentTo("maxLength: 100");
_validationConfiguration.ValidationRules.Single().FormlyValidationMessage
.Should().Be("${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters");
.Should().Be("${field?.props?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters");
}

[Test]
Expand All @@ -141,14 +141,14 @@ public void Length()
minRule.MessageTranslationId.Should().Be("validators.minLength");
minRule.FormlyTemplateOptions.Should().BeEquivalentTo("minLength: 10");
minRule.FormlyValidationMessage
.Should().Be("${field?.templateOptions?.label}:property-name: should have at least ${field?.templateOptions?.minLength}:min-value: characters");
.Should().Be("${field?.props?.label}:property-name: should have at least ${field?.templateOptions?.minLength}:min-value: characters");

var maxRule = _validationConfiguration.ValidationRules.Single(x => x.FormlyRuleName == "maxLength");
maxRule.CustomMessage.Should().BeEmpty();
maxRule.MessageTranslationId.Should().Be("validators.maxLength");
maxRule.FormlyTemplateOptions.Should().BeEquivalentTo("maxLength: 10");
maxRule.FormlyValidationMessage
.Should().Be("${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters");
.Should().Be("${field?.props?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters");
}

[Test]
Expand Down Expand Up @@ -297,7 +297,7 @@ private static void AssertNumbercMinValidationRule<T>(IFormlyValidationRule rule
rule.FormlyTemplateOptions
.Should().BeEquivalentTo("type: 'number'", $"min: {String.Format(CultureInfo.InvariantCulture, "{0}", value)}{(isEqual ? "" : $" + {GetIncrement<T>()}")}");
rule.FormlyValidationMessage
.Should().Be("${field?.templateOptions?.label}:property-name: value should be more than ${field?.templateOptions?.min}:min-value:");
.Should().Be("${field?.props?.label}:property-name: value should be more than ${field?.templateOptions?.min}:min-value:");
}

private static void AssertNumbercMaxValidationRule<T>(IFormlyValidationRule rule, T value, bool isEqual)
Expand All @@ -311,7 +311,7 @@ private static void AssertNumbercMaxValidationRule<T>(IFormlyValidationRule rule
rule.FormlyTemplateOptions
.Should().BeEquivalentTo("type: 'number'", $"max: {String.Format(CultureInfo.InvariantCulture, "{0}", value)}{(isEqual ? "" : $" - {GetIncrement<T>()}")}");
rule.FormlyValidationMessage
.Should().Be("${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:");
.Should().Be("${field?.props?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:");
}

private IFormlyValidationRule GetRuleByPropertyName(string propertyName) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void ValidationConfigurationForPatterns()
validationConfiguration.ValidationRules
.Select(x => x.FormlyValidationMessage)
.Should().BeEquivalentTo(
"${field?.templateOptions?.label}:property-name: is not in valid format",
"${field?.props?.label}:property-name: is not in valid format",
"Invalid email address format"
);
}
Expand Down Expand Up @@ -117,12 +117,12 @@ public void ValidationConfigurationForNullables()
validationConfiguration.ValidationRules
.Select(x => x.FormlyValidationMessage).Distinct()
.Should().BeEquivalentTo(
"${field?.templateOptions?.label}:property-name: is required",
"${field?.templateOptions?.label}:property-name: value should be more than ${field?.templateOptions?.min}:min-value:",
"${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:",
"${field?.templateOptions?.label}:property-name: should have at least ${field?.templateOptions?.minLength}:min-value: characters",
"${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters",
"${field?.templateOptions?.label}:property-name: is not in valid format"
"${field?.props?.label}:property-name: is required",
"${field?.props?.label}:property-name: value should be more than ${field?.templateOptions?.min}:min-value:",
"${field?.props?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:",
"${field?.props?.label}:property-name: should have at least ${field?.templateOptions?.minLength}:min-value: characters",
"${field?.props?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters",
"${field?.props?.label}:property-name: is not in valid format"
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public GreaterOrEqualToValidationRule(T value, PropertyInfo propertyInfo, Lambda

public override string FormlyValidationMessage => HasCustomMessage
? CustomMessage
: "${field?.templateOptions?.label}:property-name: value should be more than ${field?.templateOptions?.min}:min-value:";
: "${field?.props?.label}:property-name: value should be more than ${field?.templateOptions?.min}:min-value:";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public GreaterThenValidationRule(T value, PropertyInfo propertyInfo, LambdaExpre

public override string FormlyValidationMessage => HasCustomMessage
? CustomMessage
: "${field?.templateOptions?.label}:property-name: value should be more than ${field?.templateOptions?.min}:min-value:";
: "${field?.props?.label}:property-name: value should be more than ${field?.templateOptions?.min}:min-value:";
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public IsRequiredValidationRule(PropertyInfo propertyInfo, LambdaExpression expr

public override string FormlyValidationMessage => HasCustomMessage
? CustomMessage
: "${field?.templateOptions?.label}:property-name: is required";
}
: "${field?.props?.label}:property-name: is required";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public LessOrEqualToValidationRule(T value, PropertyInfo propertyInfo, LambdaExp

public override string FormlyValidationMessage => HasCustomMessage
? CustomMessage
: "${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:";
: "${field?.props?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public LessThenValidationRule(T value, PropertyInfo propertyInfo, LambdaExpressi

public override string FormlyValidationMessage => HasCustomMessage
? CustomMessage
: "${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:";
}
: "${field?.props?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public MaxLengthValidationRule(int value, PropertyInfo propertyInfo, LambdaExpre

public override string FormlyValidationMessage => HasCustomMessage
? CustomMessage
: "${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters";
: "${field?.props?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public MinLengthValidationRule(int value, PropertyInfo propertyInfo, LambdaExpre

public override string FormlyValidationMessage => HasCustomMessage
? CustomMessage
: "${field?.templateOptions?.label}:property-name: should have at least ${field?.templateOptions?.minLength}:min-value: characters";
: "${field?.props?.label}:property-name: should have at least ${field?.templateOptions?.minLength}:min-value: characters";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public PatternValidationRule(

public override string FormlyValidationMessage => HasCustomMessage
? CustomMessage
: "${field?.templateOptions?.label}:property-name: is not in valid format";
: "${field?.props?.label}:property-name: is not in valid format";
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static IHtmlContent AddCustomValidationMessages(this IHtmlHelper html, Fo
.ValidationRules
.Where(rule => rule.HasCustomMessage)
.Select(x => enableI18N
? $"{x.FormlyRuleName}: (err, field) => {AngularLocalization.Localize(x.MessageTranslationId, x.FormlyValidationMessage)}"
? $"{x.FormlyRuleName}: (_err, field) => {AngularLocalization.Localize(x.MessageTranslationId, x.FormlyValidationMessage)}"
: $"{x.FormlyRuleName}: '{x.FormlyValidationMessage}'"
);
return html.Raw($"{String.Join(",\r\n", validationMessages)}\r\n");
Expand All @@ -56,7 +56,7 @@ public static IHtmlContent AddCommonValidationMessages(this IHtmlHelper html, Fe
: $"`{rule.FormlyValidationMessage}`";
messages.Add(
rule.FormlyRuleName,
$"{{ name: '{rule.FormlyRuleName}', message: (err, field) => {message} }}"
$"{{ name: '{rule.FormlyRuleName}', message: (_err, field) => {message} }}"
);
}
}
Expand Down