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

Update Property.System.String.cshtml template to set option value for… #43

Closed Budsy closed 7 years ago

Budsy commented 7 years ago

Suggested update sets radio button options value to the displayed string. (Some users may prefer indexes instead?) All radio button options were hard coded as value="option1" . This makes it hard to retrieve the selected value on postback if reading the Request.Params . For example, without this change the examples page rendered the radio button list of OS choices to the following, showing all values set to 'option1':

<div class="radio"> <label> <input type="radio" name="os" value="option1" > OSX </label> </div> <div class="radio"> <label> <input type="radio" name="os" value="option1" > IOS </label> </div> <div class="radio"> <label> <input type="radio" name="os" value="option1" checked> Windows </label> </div> <div class="radio"> <label> <input type="radio" name="os" value="option1" > Android </label> </div>

mcintyre321 commented 7 years ago

You've found a bug, I think.

it should actually be @option.Item2 though - change it and I will accept the PR.

The idea for choices is that you can return a single value (which gets mapped into a Tuple<string, string> in the view), or a Tuple<string, string> where Item1 is the display name, and Item2 is the value (so you can have different values).

I should probably have made a type like

public class NameAndValue { public string DisplayName {get;set;} public string Value {get;set:} }

and map both string and Tuple<string, string> into it. Anyway I never quite got round it

mcintyre321 commented 7 years ago

Thanks for the PR @Budsy !