-
-
Notifications
You must be signed in to change notification settings - Fork 368
feat(EditorForm): add IsRenderWhenValueChanged parameter #7138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2b17d48
feat: 增加 IEditorFormValueChanged 接口
ArgoZhang b810a39
feat: 实现通知功能
ArgoZhang 23614a8
doc: 更新联动示例
ArgoZhang d2bc8b3
Merge branch 'main' into feat-table
ArgoZhang 856ba2b
feat: 增加 IsRenderWhenValueChanged 参数
ArgoZhang 544d005
chore: bump version 10.0.1
ArgoZhang 3ff3e02
refactor: 重新设计逻辑
ArgoZhang ff7135e
refactor: 精简代码
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 0 additions & 21 deletions
21
src/BootstrapBlazor.Server/Components/Components/DemoTableEditTemplate.razor
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
src/BootstrapBlazor.Server/Components/Components/DemoTableEditTemplate.razor.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
@@ -40,6 +40,13 @@ public partial class TablesEdit | |
|
|
||
| private bool _useGroup = false; | ||
|
|
||
| private string? GetEducationDesc(EnumEducation? item) => item switch | ||
| { | ||
| EnumEducation.Primary => Localizer["TablesEditTemplateDisplayDetail1"], | ||
| EnumEducation.Middle => Localizer["TablesEditTemplateDisplayDetail2"], | ||
| _ => "" | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
@@ -12,7 +12,7 @@ namespace BootstrapBlazor.Components; | |
| /// 编辑表单基类 | ||
| /// </summary> | ||
| [CascadingTypeParameter(nameof(TModel))] | ||
| public partial class EditorForm<TModel> : IShowLabel | ||
| public partial class EditorForm<TModel> : IShowLabel, IDisposable | ||
ArgoZhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| private string? ClassString => CssBuilder.Default("bb-editor") | ||
| .AddClassFromAttributes(AdditionalAttributes) | ||
|
|
@@ -159,6 +159,12 @@ public partial class EditorForm<TModel> : IShowLabel | |
| [NotNull] | ||
| public string? PlaceHolderText { get; set; } | ||
|
|
||
| /// <summary> | ||
ArgoZhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// 获得/设置 当值变化时是否重新渲染组件 默认 false | ||
| /// </summary> | ||
| [Parameter] | ||
| public bool IsRenderWhenValueChanged { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 级联上下文 EditContext 实例 内置于 EditForm 或者 ValidateForm 时有值 | ||
| /// </summary> | ||
|
|
@@ -209,6 +215,11 @@ protected override void OnInitialized() | |
| { | ||
| base.OnInitialized(); | ||
|
|
||
| if (CascadedEditContext != null) | ||
| { | ||
| CascadedEditContext.OnFieldChanged += NotifyValueChanged; | ||
| } | ||
|
|
||
| if (CascadedEditContext != null && IsSearch is not true) | ||
| { | ||
| var message = Localizer["ModelInvalidOperationExceptionMessage", nameof(EditorForm<TModel>)]; | ||
|
|
@@ -298,4 +309,25 @@ private RenderFragment AutoGenerateTemplate(IEditorItem item) => builder => | |
| private RenderFragment<object>? GetRenderTemplate(IEditorItem item) => IsSearch.Value && item is ITableColumn col | ||
| ? col.SearchTemplate | ||
| : item.EditTemplate; | ||
|
|
||
| private void NotifyValueChanged(object? sender, FieldChangedEventArgs args) | ||
| { | ||
| // perf: 判断是否在编辑状态避免不必要的重绘 | ||
| if (IsRenderWhenValueChanged) | ||
| { | ||
| StateHasChanged(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
| public void Dispose() | ||
| { | ||
| if (CascadedEditContext != null) | ||
| { | ||
| CascadedEditContext.OnFieldChanged -= NotifyValueChanged; | ||
| } | ||
| GC.SuppressFinalize(this); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.