mcintyre321 / FormFactory

MVC5, Core or standalone - Generate rich HTML5 forms from your ViewModels, or build them programatically
http://formfactoryaspmvc.azurewebsites.net/
MIT License
304 stars 102 forks source link

Required attribute #65

Closed adaml984 closed 6 years ago

adaml984 commented 6 years ago

Hello, Form the beginning, here's part of my viewmodel, two sample properties: [Required] public string CompanyName { get; set; }

[Required] [Radio] public ContractType ContractType { get; set; }

Here's how I build form:

@{ var props = FF.PropertiesFor(Model); @props.Render(Html); }

When I post form and CompanyName is empty/null I don't get validation message that says CompanyName is required. On the other hand when ContractType enum value is not set I get message that says ContractType is required. It seems that Required on string properties does not work or I'm missusing it. Could you clarify how to use that attribute?

mcintyre321 commented 6 years ago

Can you try using the [StringLength] attribute to ensure there are some characters?

It's been a while since I've worked on this, but I vaguely remember that strings are a bit funny, due to whitespace being a valid value.

There's maybe some work to needed on https://github.com/mcintyre321/FormFactory/blob/master/FormFactory/UnobtrusiveValidation/ClientValidationRules.cs

adaml984 commented 6 years ago

thanks, I got this working.

Best regards, Adam