Comments (2)
I'm answering my own question but I'm open to suggestions to improve my way, if any :)
I've modified Form.Property.cshtml to have the first few lines to look like this:
bool IsHiddenOnEdit = false;
var attrs = Model.GetCustomAttributes().Where(a => a.GetType().Name == "DataTypeAttribute").ToList();
foreach(var a in attrs)
{
DataTypeAttribute dta = (DataTypeAttribute)a;
if (dta.CustomDataType == "HiddenOnEdit")
{
IsHiddenOnEdit = true;
}
}
if (Model.IsHidden || (IsHiddenOnEdit && ViewBag.EditMode == true))
{
<div style="display: none">@Html.BestProperty(Model)</div>
And I've annotated the propety with [DataType("HiddenOnEdit")] where needed.
from formfactory.
Glad you managed to get it to work for you!
It would be great to create a base class, so that new attributes wouldn't have to modify the template, and could be added by users without modifying the core.
FormFactory core project:
public abstract class FormFactoryPropertyAttribute : Attribute
{
public abstract void ApplyToProperty(PropertyVm vm);
}
Form.Property.cshtml
foreach(var a in attrs.OfType<FormFactoryPropertyAttribute>())
{
a.ApplyToProperty(Model, Html);
}
And then in your project
class IsHiddenOnEdit : FormFactoryPropertyAttribute {
public override void ApplyToProperty(PropertyVm vm, FfHtmlHelper htmlHelper)
{
if (htmlHelper.ViewData["EditMode"] as bool? ?? false)
vm.IsHidden = true;
}
}
I'll add this when I get a chance, but it might not be for a while. If you're up for the challenge, pull requests are gratefully accepted!
from formfactory.
Related Issues (20)
- Installation not working with .net core 3+ HOT 1
- Sorry, an error occurred while processing your request. HOT 2
- Improvement for radio buttons
- The sample site doesn't load HOT 1
- Looking a way to extend FormFactory functionalities HOT 5
- For the dynamic form submit, how to add an additional Save button which does not do FF client side validation?
- add and remove actions don't work for the editable collection
- Validation not working on programmatically created form HOT 1
- Live Website Docs are Down HOT 4
- Asp Net Core 3.0 AggregateException The partial view 'FormFactory/Form.Property' was not found. HOT 9
- File Upload Control HOT 1
- Multiple Textbox HOT 1
- IIS Publish Error HOT 1
- Dynamic forms from Propertyvm HOT 2
- Repeatable row/table? HOT 2
- Client validations not working when using PropertyVms to create Dynamic Forms. HOT 3
- Documentation on custom templates? HOT 2
- No example provided for a server side validation HOT 1
- FormFactory Templates installs all files in root of project
- Does this work with Blazor? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from formfactory.