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

Trying to get started with FormFactory.AspMvc #26

Closed craig2l closed 8 years ago

craig2l commented 8 years ago

Sorry to ask such a naïve question, but I am just starting with FormFactory.AspMvc and haven't been able to get off ground. Downloaded Nuget packages (including AspMvc and Templates). Placed the following in one of my edit forms (cshtml): @Html.PropertiesFor(Model).Render(Html)

PropertiesFor is not recognized. No doubt doing something stupid. Thanks, Craig

mcintyre321 commented 8 years ago

Add

@using FormFactory;
@using FormFactory.AspMvc;

To your view

craig2l commented 8 years ago

Harry, thanks for the quick reply. I had the second reference but not the first. Works like a charm. Very impressive what you’ve done. Now I’m just trying to figure out where I alter things in your templates to make the labels adjacent to the values (think the bootstrap class I want is form-horizontal).

This is indeed a very nice contribution to the community.

Craig

From: Harry McIntyre [mailto:notifications@github.com] Sent: Monday, June 06, 2016 11:55 AM To: mcintyre321/FormFactory FormFactory@noreply.github.com Cc: craig2l craig@d-lcorp.com; Author author@noreply.github.com Subject: Re: [mcintyre321/FormFactory] Trying to get started with FormFactory.AspMvc (#26)

Add

@using FormFactory; @using FormFactory.AspMvc;

To your view

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mcintyre321/FormFactory/issues/26#issuecomment-224053155 , or mute the thread https://github.com/notifications/unsubscribe/AFBafjmj5B_ePrgOGIrQh_Mk_nwEFS-Yks5qJGzvgaJpZM4IvMag . https://github.com/notifications/beacon/AFBafqkYcicLlphk5Zs3-BlFmxW_GGfbks5qJGzvgaJpZM4IvMag.gif

craig2l commented 8 years ago

Harry,

Sorry to bother you with another question. Incidentally, I am starting to get comfortable with modifying your various templates and did successfully make the change to make my form horizontal and changed the format of the date as well.

Now trying to suppress the display of my Id column. In my model I have the Id field set to [HiddenInput(DisplayValue = false)]. When I’m debugging, however, in Form.Property.cshtml, the Model.IsHidden value is false, but the Model.GetCustomAttributes() returns System.Web.Mvc.HiddenInputAttribute. Any guidance here? Thank you!

Craig

From: Harry McIntyre [mailto:notifications@github.com] Sent: Monday, June 06, 2016 11:55 AM To: mcintyre321/FormFactory FormFactory@noreply.github.com Cc: craig2l craig@d-lcorp.com; Author author@noreply.github.com Subject: Re: [mcintyre321/FormFactory] Trying to get started with FormFactory.AspMvc (#26)

Add

@using FormFactory; @using FormFactory.AspMvc;

To your view

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mcintyre321/FormFactory/issues/26#issuecomment-224053155 , or mute the thread https://github.com/notifications/unsubscribe/AFBafjmj5B_ePrgOGIrQh_Mk_nwEFS-Yks5qJGzvgaJpZM4IvMag . https://github.com/notifications/beacon/AFBafqkYcicLlphk5Zs3-BlFmxW_GGfbks5qJGzvgaJpZM4IvMag.gif

mcintyre321 commented 8 years ago

If you look at PropertyVm.cs#L58

 IsHidden = pi.GetCustomAttributes(true).OfType<DataTypeAttribute>().Any(x => x.CustomDataType == "Hidden");

so you need to use:

[DataType("Hidden")] 

rather than the Mvc attribute. It's been a while since I wrote this, but I think this is probably to avoid a dependency on Mvc in the core library. If I ever get the time, I'd like to create a/ a pluggable way to add support for external attributes, and b/ a set of built in attributes, and c/ some better documentation!

craig2l commented 8 years ago

Harry,

Thank you for taking the time to answer this; I really appreciate your generosity.

I actually “solved” this issue myself, though I’m sure in a much less elegant manner than your solution. In the Form.Property.cshml, at the top where you check for:

If (Model.IsHidden)…

I replaced this with:

If (Model.IsHidden || Model.GetCustomAttributes().OfType(System.Mvc.HiddenInputAttribute>.Count > 0)…

It works, but you’ve shown me that this code should obviously be pushed down into the IsHidden call. Thank you! Again, an impressive product!

Craig

From: Harry McIntyre [mailto:notifications@github.com] Sent: Tuesday, June 07, 2016 1:22 AM To: mcintyre321/FormFactory FormFactory@noreply.github.com Cc: craig2l craig@d-lcorp.com; Author author@noreply.github.com Subject: Re: [mcintyre321/FormFactory] Trying to get started with FormFactory.AspMvc (#26)

If you look at PropertyVm.cs#L58 https://github.com/mcintyre321/FormFactory/blob/f391a4c8920f6dae9b38fcfdee1d301b75379d9b/FormFactory/PropertyVm.cs#L58

IsHidden = pi.GetCustomAttributes(true).OfType().Any(x => x.CustomDataType == "Hidden");

so you need to use:

[DataType("Hidden")]

rather than the Mvc attribute. It's been a while since I wrote this, but I think this is probably to avoid a dependency on Mvc in the core library. If I ever get the time, I'd like to create a/ a pluggable way to add support for external attributes, and b/ a set of built in attributes, and c/ some better documentation!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mcintyre321/FormFactory/issues/26#issuecomment-224212483 , or mute the thread https://github.com/notifications/unsubscribe/AFBaft2UOzJz5rx0AYj9-KQ0Ze3O1jIAks5qJSongaJpZM4IvMag . https://github.com/notifications/beacon/AFBafub5I008UdVsxkIhNhDw7GN54GYyks5qJSongaJpZM4IvMag.gif