diff --git a/components/form/GenerateFormItem.razor.cs b/components/form/GenerateFormItem.razor.cs index d71196a8..0f48d178 100644 --- a/components/form/GenerateFormItem.razor.cs +++ b/components/form/GenerateFormItem.razor.cs @@ -295,6 +295,8 @@ public partial class GenerateFormItem : ComponentBase var funcType = typeof(Func<>); var constructedFuncType = funcType.MakeGenericType(property.PropertyType); + var isReadOnly = property.GetCustomAttribute()?.IsReadOnly ?? false; + return builder => { builder.OpenComponent(0, constructedType); @@ -303,6 +305,7 @@ public partial class GenerateFormItem : ComponentBase new Action(o => property.SetValue(model, o))); builder.AddAttribute(2, "ValueChanged", eventCallback); builder.AddAttribute(3, "ValueExpression", Expression.Lambda(constructedFuncType, exp)); + if (isReadOnly) builder.AddAttribute(4, "Disabled", isReadOnly); builder.CloseComponent(); }; } diff --git a/site/AntDesign.Docs/Demos/Components/Form/demo/GenerateFormItem_.razor b/site/AntDesign.Docs/Demos/Components/Form/demo/GenerateFormItem_.razor index ebeed638..8d9ae300 100644 --- a/site/AntDesign.Docs/Demos/Components/Form/demo/GenerateFormItem_.razor +++ b/site/AntDesign.Docs/Demos/Components/Form/demo/GenerateFormItem_.razor @@ -7,11 +7,11 @@ OnFinishFailed="OnFinishFailed" LabelColSpan="8" WrapperColSpan="16"> - + @@ -52,7 +52,9 @@ [DisplayName("DefinitionsTest")] public string J { get; set; } - // [ValidateComplexType] + [DisplayName("ReadOnlyTest"), ReadOnly(true)] + public string K { get; set; } + public ModelChild ModelChild { get; set; } } @@ -84,7 +86,7 @@ [Required] public IEnumerable II { get; set; } public string JJ { get; set; } - + // [ValidateComplexType] public ModelChild2 ModelChild2 { get; set; } } @@ -127,18 +129,18 @@ if (structurePath == "J") { return @; + + + + ; } if (structurePath == "ModelChild.JJ") { return @; + + + + ; } return null; }