Пример #1
0
        protected virtual void ValidateUsingDataAnnotation(object newValidationValue)
        {
            ValidationStarted?.Invoke();

            var messages = new ValidationMessageStore(EditContext);

            EditContextValidator.ValidateField(EditContext, messages, fieldIdentifier, MessageLocalizer ?? Options.ValidationMessageLocalizer);

            var matchStatus = messages[fieldIdentifier].Any()
                ? ValidationStatus.Error
                : ValidationStatus.Success;

            var matchMessages = matchStatus == ValidationStatus.Error
                ? messages[fieldIdentifier]
                : null;

            // Sometime status will stay the same and error message will change
            // eg. StringLength > empty string > Required
            if (Status != matchStatus || !Comparers.AreEqual(Messages?.ToArray(), matchMessages?.ToArray()))
            {
                Status   = matchStatus;
                Messages = matchMessages;

                NotifyValidationStatusChanged(Status, Messages);
            }
        }
Пример #2
0
        /// <inheritdoc/>
        public void Validate(IValidation validation, object newValidationValue)
        {
            validation.NotifyValidationStarted();

            var messages = new ValidationMessageStore(validation.EditContext);

            EditContextValidator.ValidateField(validation.EditContext, messages, validation.FieldIdentifier, validation.MessageLocalizer ?? Options.ValidationMessageLocalizer);

            var matchStatus = messages[validation.FieldIdentifier].Any()
                ? ValidationStatus.Error
                : ValidationStatus.Success;

            var matchMessages = matchStatus == ValidationStatus.Error
                ? messages[validation.FieldIdentifier]
                : null;

            validation.NotifyValidationStatusChanged(matchStatus, matchMessages);
        }