Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation not working on programmatically created form #109

Open
nutkraker opened this issue Sep 15, 2021 · 1 comment
Open

Validation not working on programmatically created form #109

nutkraker opened this issue Sep 15, 2021 · 1 comment

Comments

@nutkraker
Copy link

Hi!

I am trying to create a form programmatically as the form fields are being saved in a database so the users can create their own forms with their own data. This part I have working and the forms are displayed exactly as they should.

The only issue is that when the "NotOptional" value is set to true, there is no validation done on the form when it is submitted.

Below is an example using the demo "Programmatically created form" data and when it is submitted, it submits and does not show that the fields are required or cancel the submission like it does on the first demo called "Auto Complete" here: http://formfactory.apphb.com/

Any idea why this is happening and not validating?

<form action="/home/save" method="POST"> @{ var formModel = new[] { new PropertyVm(typeof(string), "username") { DisplayName = "Username", NotOptional = true, }, new PropertyVm(typeof(string), "password") { DisplayName = "Password", NotOptional = true, GetCustomAttributes = () => new object[] {new PasswordAttribute()} }, new PropertyVm(typeof(string), "os") { DisplayName = "Operating System", NotOptional = true, Choices = new List<string>() {"OSX", "IOS", "Windows", "Android"}, Value = "Windows", //Preselect windows GetCustomAttributes = () => new object[] {new RadioAttribute()}, }, new PropertyVm(typeof(string) , "textmessage") { DisplayName = "Type a message:", NotOptional =false, GetCustomAttributes = () => new object[] { new MultilineTextAttribute(), new DisplayAttribute(){Prompt = "placeholder??"}, new SuggestionsUrlAttribute( "/home/CountrySuggestions" ) }, }, }; @formModel.Render( Html ) } <input type="submit" value="submit" /> </form>

@jromerus
Copy link

jromerus commented Sep 19, 2022

Hi, it seems that NotOptional is not appropiate for that. I have just tested and it works adding a RequiredAttribute to the property:

var formModel = new[] { new PropertyVm(typeof(string), "username") { DisplayName = "UserName", GetCustomAttributes = () => new object[] { new RequiredAttribute()} }, new PropertyVm(typeof(string), "password") { DisplayName = "Password", GetCustomAttributes = () => new object[] {new PasswordAttribute(), new RequiredAttribute()} }, new PropertyVm(typeof(string), "os") { DisplayName = "Operating System", NotOptional = true, Choices = new List<string>() {"OSX", "IOS", "Windows", "Android"}, Value = "Windows", //Preselect windows GetCustomAttributes = () => new object[] {new RadioAttribute()}, } };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants