mcintyre321 / FormFactory

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

How to dynamically disable an edit? #57

Closed gingters closed 6 years ago

gingters commented 6 years ago

Hi,

I have a enum, and the user should select one of the entries in the enum with a radio box, and a textbox which should only be enabled when a certain element in the dropdown is selected.

Example:

Please select an item:

If other, what other item did you select?: [Textbox] (should be editable only if Other is selected above.)

In short, I want to replicate the Fomerole Type from this reporting form but with a bit more validation logic: https://docs.google.com/forms/d/e/1FAIpQLSeYI4R29n-n6eMQTxoL_Nh5rF26NUGxQQqt5dOH7YCT2A1gzA/viewform

Besides that, I can't get it working. I specified this:

[Display(Name = "Fumerole type")]
[Radio]
[Description("If your type isn't listed, please use the other.")]
public FumeroleType FumeroleType { get; set; }

With FumeroleType being my enum, but it renders as a dropdown and not as a radio button list.

mcintyre321 commented 6 years ago

Hi, sorry I missed this. Are you still having this problem?

mcintyre321 commented 6 years ago

Think this might work:


public class SomeViewModel{ 

        public FumeroleType FumeroleType { get; set; }
        public IEnumerable<FumeroleType > FumeroleType _choices()
        {
            yield return new FumeroleType {Value = "FirstItem"}.DisplayName("FirstItem");
            yield return new FumeroleType {Value = "SecondItem"}.DisplayName("SecondItem");
            yield return new FumeroleType {Value = "ThirdItem"}.DisplayName("ThirdItem");
            yield return new OtherFumeroleType {Value = "Other"}.DisplayName("Other");
        };

       public class FumeroleType 
       {
           public string Value { get; set; }
        }
       public class OtherFumeroleType : FumeroleType 
       {
            public string OtherValue {get;set;}
        }
    }