mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-02 20:17:58 +08:00
fix: fix the form binding value bug (#324)
This commit is contained in:
parent
f11fd0e103
commit
a7253af7c8
@ -326,7 +326,8 @@ namespace AntDesign
|
||||
var node = GetNodeByValue(_nodelist, defaultValue);
|
||||
SetSelectedNodeWithParent(node, ref _selectedNodes);
|
||||
_renderNodes = _selectedNodes;
|
||||
SetValue(node.Value);
|
||||
if (node != null)
|
||||
SetValue(node.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -5,6 +5,16 @@ namespace AntDesign
|
||||
{
|
||||
public partial class DatePicker : DatePickerBase<DateTime>
|
||||
{
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
if (Value != null && Value != DateTime.MinValue)
|
||||
{
|
||||
ChangeValue(Value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void OnInput(ChangeEventArgs args, int index = 0)
|
||||
{
|
||||
if (args == null)
|
||||
|
@ -451,7 +451,7 @@ namespace AntDesign
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_dropDown.Hide();
|
||||
_dropDown?.Hide();
|
||||
}
|
||||
|
||||
public async Task Focus(int index = 0)
|
||||
@ -559,6 +559,11 @@ namespace AntDesign
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改值
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="index"></param>
|
||||
public virtual void ChangeValue(DateTime value, int index = 0)
|
||||
{
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ namespace AntDesign
|
||||
{
|
||||
base.OnInitialized();
|
||||
SetClass();
|
||||
CurrentValue = DefaultValue;
|
||||
CurrentValue = Value ?? DefaultValue;
|
||||
}
|
||||
|
||||
private void SetClass()
|
||||
|
@ -49,7 +49,7 @@ namespace AntDesign
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
this._isChecked = Checked;
|
||||
this._isChecked = Value ? Value : Checked;
|
||||
base.OnInitialized();
|
||||
}
|
||||
|
||||
|
@ -1,77 +1,85 @@
|
||||
@using System.Text.Json;
|
||||
|
||||
<Form Model="@model"
|
||||
LabelCol="new ColLayoutParam { Span = 8 }"
|
||||
WrapperCol="new ColLayoutParam { Span = 16 }"
|
||||
OnFinish="OnFinish"
|
||||
OnFinishFailed="OnFinishFailed"
|
||||
Size="@model.Size">
|
||||
<FormItem Label="Form Size">
|
||||
<RadioGroup @bind-Value="@context.Size">
|
||||
<Radio RadioButton Value="@AntSizeLDSType.Small">Small</Radio>
|
||||
<Radio RadioButton Value="@AntSizeLDSType.Default">Default</Radio>
|
||||
<Radio RadioButton Value="@AntSizeLDSType.Large">Large</Radio>
|
||||
</RadioGroup>
|
||||
</FormItem>
|
||||
<Form Model="@model"
|
||||
LabelCol="new ColLayoutParam { Span = 8 }"
|
||||
WrapperCol="new ColLayoutParam { Span = 16 }"
|
||||
OnFinish="OnFinish"
|
||||
OnFinishFailed="OnFinishFailed"
|
||||
Size="@model.Size">
|
||||
<FormItem Label="Form Size">
|
||||
<RadioGroup @bind-Value="@context.Size">
|
||||
<Radio RadioButton Value="@AntSizeLDSType.Small">Small</Radio>
|
||||
<Radio RadioButton Value="@AntSizeLDSType.Default">Default</Radio>
|
||||
<Radio RadioButton Value="@AntSizeLDSType.Large">Large</Radio>
|
||||
</RadioGroup>
|
||||
</FormItem>
|
||||
|
||||
<FormItem Label="Input">
|
||||
<Input @bind-Value="@context.Input" />
|
||||
</FormItem>
|
||||
<FormItem Label="InputArea">
|
||||
<TextArea @bind-Value="@context.InputArea" />
|
||||
</FormItem>
|
||||
<FormItem Label="Cascader">
|
||||
<Cascader @bind-Value="@context.Cascader" Options="districts" />
|
||||
</FormItem>
|
||||
<FormItem Label="DatePicker">
|
||||
<DatePicker @bind-Value="@context.DatePicker" />
|
||||
</FormItem>
|
||||
<FormItem Label="InputNumber">
|
||||
<AntDesign.InputNumber @bind-Value="@context.Number" />
|
||||
</FormItem>
|
||||
<FormItem Label="Switch">
|
||||
<Switch @bind-Value="@context.Switch" />
|
||||
</FormItem>
|
||||
<FormItem Label="Switch">
|
||||
<RadioGroup @bind-Value="@context.Radio">
|
||||
<Radio RadioButton Value="@("Hangzhou")">Hangzhou</Radio>
|
||||
<Radio RadioButton Value="@("Shanghai")">Shanghai</Radio>
|
||||
<Radio RadioButton Value="@("Beijing")">Beijing</Radio>
|
||||
<Radio RadioButton Value="@("Chengdu")">Chengdu</Radio>
|
||||
</RadioGroup>
|
||||
</FormItem>
|
||||
<FormItem WrapperCol="new ColLayoutParam{ Offset = 8, Span = 16 }">
|
||||
<Button HtmlType="submit">
|
||||
Button
|
||||
</Button>
|
||||
</FormItem>
|
||||
</Form>
|
||||
<FormItem Label="Input">
|
||||
<Input @bind-Value="@context.Input" />
|
||||
</FormItem>
|
||||
<FormItem Label="InputArea">
|
||||
<TextArea @bind-Value="@context.InputArea" />
|
||||
</FormItem>
|
||||
<FormItem Label="Cascader">
|
||||
<Cascader @bind-Value="@context.Cascader" Options="districts" />
|
||||
</FormItem>
|
||||
<FormItem Label="DatePicker">
|
||||
<DatePicker @bind-Value="@context.DatePicker" />
|
||||
</FormItem>
|
||||
<FormItem Label="InputNumber">
|
||||
<AntDesign.InputNumber @bind-Value="@context.Number" />
|
||||
</FormItem>
|
||||
<FormItem Label="Switch">
|
||||
<Switch @bind-Value="@context.Switch" />
|
||||
</FormItem>
|
||||
<FormItem Label="Radio">
|
||||
<RadioGroup @bind-Value="@context.Radio">
|
||||
<Radio RadioButton Value="@("Hangzhou")">Hangzhou</Radio>
|
||||
<Radio RadioButton Value="@("Shanghai")">Shanghai</Radio>
|
||||
<Radio RadioButton Value="@("Beijing")">Beijing</Radio>
|
||||
<Radio RadioButton Value="@("Chengdu")">Chengdu</Radio>
|
||||
</RadioGroup>
|
||||
</FormItem>
|
||||
<FormItem WrapperCol="new ColLayoutParam{ Offset = 8, Span = 16 }">
|
||||
<Button HtmlType="submit">
|
||||
Button
|
||||
</Button>
|
||||
</FormItem>
|
||||
</Form>
|
||||
|
||||
@model.Switch
|
||||
@code
|
||||
{
|
||||
public class Model
|
||||
{
|
||||
public string Size { get; set; } = AntSizeLDSType.Small;
|
||||
public string Input { get; set; }
|
||||
public string InputArea { get; set; }
|
||||
public string Cascader { get; set; }
|
||||
public DateTime DatePicker { get; set; }
|
||||
public double Number { get; set; }
|
||||
public bool Switch { get; set; }
|
||||
public string Radio { get; set; }
|
||||
public string Input { get; set; } = "input";
|
||||
public string InputArea { get; set; } = "inputArea";
|
||||
public string Cascader { get; set; } = "11";
|
||||
public DateTime DatePicker { get; set; } = DateTime.Now;
|
||||
public double Number { get; set; } = 1;
|
||||
public bool Switch { get; set; } = true;
|
||||
public string Radio { get; set; } = "Beijing";
|
||||
}
|
||||
|
||||
private Model model = new Model();
|
||||
|
||||
private List<CascaderNode> districts = new List<CascaderNode>
|
||||
{
|
||||
{
|
||||
new CascaderNode()
|
||||
{
|
||||
Value = "1",
|
||||
Label = "zhejiang",
|
||||
Label = "浙江",
|
||||
Children = new []
|
||||
{
|
||||
new CascaderNode {Value = "11", Label = "hangzhou"},
|
||||
},
|
||||
{
|
||||
new CascaderNode {Value = "11", Label = "杭州"},
|
||||
new CascaderNode {Value = "12", Label = "温州"},
|
||||
}
|
||||
},
|
||||
new CascaderNode()
|
||||
{
|
||||
Value = "2",
|
||||
Label = "上海",
|
||||
}
|
||||
};
|
||||
|
||||
@ -84,4 +92,5 @@
|
||||
{
|
||||
Console.WriteLine($"Failed:{JsonSerializer.Serialize(model)}");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user