EdiorForm 及 ValidateForm.ValueChagnedFields 問題 #2078
Answered
by
ArgoZhang
ElecSheep224
asked this question in
Q&A
-
目前的使用情境上 EditorForm 及 ValidateForm 綁定的模型中有一類型為 String 名稱為 Range 的欄位,此欄位應需求不直接使用 EditorItem 組件生成編輯框供使用者輸入,改為使用 EditTemplate 組件並內含兩個 BootstrapInput 組件 bind 不屬於前述模型的欄位 _rangeMin 及 _rangeMax 進行編輯,並於 ValidateForm 之 OnValidSubmit 綁定之方法中將 _rangeMin 及 _rangeMax 之值組成並賦值給 Range 欄位,但 ValidateForm.ValueChagnedFields 並未新增與 Range 欄位有關的紀錄。 想請問 ValidateForm.ValueChagnedFields 並未新增與 Range 欄位有關的紀錄,是否是因為透過後端賦值的方式無法觸發 Change 事件? Edit.razor <ValidateForm @ref="EditorValidateForm" Model="@EditorData" OnValidSubmit="SaveData">
<EditorForm Model="@EditorData" AutoGenerateAllItem="false">
<FieldItems>
<EditorItem @bind-Field="@context.Range">
<EditTemplate Context="value">
<BootstrapInputGroup class="mt-2">
<BootstrapInput @bind-Value="@_rangeMin"/>
<BootstrapInput @bind-Value="@_rangeMax"/>
</BootstrapInputGroup>
</EditTemplate>
</EditorItem>
</FieldItems>
</EditorForm>
</ValidateForm> Edit.razor.cs public partial class Edit
{
protected EditorData? EditorData { get; set; } = new();
private double _rangeMin = default!;
private double _rangeMax = default!;
protected override async Task SaveData(EditContext editContext)
{
EditorData.Range= Math.Min(_rangeMin, _rangeMax).ToString() + "," + Math.Max(_rangeMin, _rangeMax).ToString();
}
} EditorData.cs public class EditorData
{
public string Range{ get; set; }
} |
Beta Was this translation helpful? Give feedback.
Answered by
ArgoZhang
Dec 1, 2023
Replies: 1 comment
-
@ElecSheep224 大概率是因为你自定义模板导致内部无法获得这个元素 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ArgoZhang
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ElecSheep224 大概率是因为你自定义模板导致内部无法获得这个元素