Sharprompt icon indicating copy to clipboard operation
Sharprompt copied to clipboard

Prompt.Bind support for IntegerValidator (MinValue, MaxValue), DefaultValue attributes

Open abrasat opened this issue 1 year ago • 2 comments

Does Prompt.Bind support also the IntegerValidator (MinValue, MaxValue), DefaultValue attributes in the model? I tried this :

public class MyModel
{
    [Display(Name = "MyParam")]
    [IntegerValidator(MinValue = 1, MaxValue = 3)]
    [DefaultValue(2)]
    [Required]
    public int MyParam { get; set; }
}
...
var myModel = Prompt.Bind<MyModel>();

but see (0) as default, and can also enter any integer value.

abrasat avatar Jun 13 '24 14:06 abrasat

I think the following definition achieves the same thing.

public class MyModel
{
    [Display(Name = "MyParam")]
    [Range(1, 3)]
    [Required]
    public int MyParam { get; set; } = 2;
}

shibayan avatar Jun 15 '24 16:06 shibayan

You are right, it works. Thanks! Where can I find the list with the supported annotations?

abrasat avatar Jun 17 '24 05:06 abrasat

Since it uses the standard C# Validator, almost all Data Annotations classes can be used.

shibayan avatar Jan 08 '25 07:01 shibayan