mcintyre321 / FormFactory

MVC5, Core or standalone - Generate rich HTML5 forms from your ViewModels, or build them programatically

Home Page:http://formfactoryaspmvc.azurewebsites.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Required attribute

adaml984 opened this issue · comments

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?

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

thanks, I got this working.

Best regards,
Adam