London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
AI OnAI Off
London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
You could create your custom validation attribute, like this:
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public sealed class RequiredForPublishAttribute : ValidationAttribute
{
const string defaultMessage = "{0} is a required property!";
private bool IsDefaultMessage = true;
public PropertyRequired()
{
}
public PropertyRequired(string message)
{
ErrorMessage = message;
IsDefaultMessage = false;
}
public override bool IsValid(object value)
{
return !value.IsNull();
}
public override string FormatErrorMessage(string name)
{
return IsDefaultMessage ? string.Format(defaultMessage, name) : ErrorMessage;
}
}
...then just replace [Required] with [RequiredForPublish].
We have request for customers that models with
Required
-attributes should not render that "create view with required fields only", inexperienced users gets confused and don't understand where all other fields are.If we could set
[Required(SaveAction.Publish)]
or something, we could tell that theseRequired
-fields are required when publishing, not for creating etc.Or maybe there should be a possibility to annotate the model with something that forces showing complete edit view on creation?
I understand the customers request and feel it would be a nice feature to make a more solid experience for some customers.