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

Looking a way to extend FormFactory functionalities

michael-ye opened this issue · comments

We are looking for a "postback" kind of functionality on form field change event.

I can make this work by adding a property to the ProjectVM

//Adding a DoPostback property to the PropertyVM
public class PropertyVM : IHasDisplayName
{
...
...
public string DoPostback {get; set;}
}

And modifying the FormFactory rendering razor view classes, for example in Property.System.String.cshtml, modifying the following line of code and adding onchange attribute:

   <select name="@Model.Name" onchange="@Model.DoPostBack" class="form-control" @Html.Raw(Model.Readonly()) @Html.Raw(Model.Disabled()) @Html.Raw(isRequired ? "required" : "")>

Then, in the the asp.net core razor view file, handle the DoPostBack with javascript:

@using FormFactory

@model List<PropertyVm>

<div class="row">
    <div class="span1">&nbsp;</div>
    <div class="col-md-5">
        <form name="FFDemoForm" asp-area="Assessments" asp-controller="Assessment" asp-action="save" method="post">

            @Model.Render(Html)

            <input type="submit" value="submit" />
        </form>

    </div>
</div>

<script>
    function DoPostBack() {

        alert("Popup On Change demo - you are about to trigger an onchange event and doing  postback.");

        document.FFDemoForm.action = "/Assessments/Assessment/Postback";
        document.FFDemoForm.submit();

    };
</script>

If a PropertyVM with DoPostBack property set, at changes, the view will popup and then do a Postback. This works but I am looking for advice on how we can do this without directly changing FormFactory. Is there a way that we can extend FF and accomplish what we need?

Thanks, I think this will solve the problem of modifying PropertyVm.

Can you suggest how to avoid modifying Property.System.String.cshtml (adding the onchange attribute) and all other types?

Answer my own question here. In FormFactory project, there is a _ReadMe.txt file under the folder Views/Shared/FormFactory which indicates that we can modify these view files and override the ones that would be loaded from the FormFactory assembly.

I think this would work for us.

This is working on asp.net core 3.1

Thank you for the great work. It has made our work a lot simpler!