Skip to content

Commit d274bfb

Browse files
committed
2 parents 38a9e47 + 605aca1 commit d274bfb

File tree

10 files changed

+121
-51
lines changed

10 files changed

+121
-51
lines changed

src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<PackageReference Include="BootstrapBlazor.PdfViewer" Version="9.0.6" />
6767
<PackageReference Include="BootstrapBlazor.Player" Version="9.0.2" />
6868
<PackageReference Include="BootstrapBlazor.RDKit" Version="9.0.2" />
69-
<PackageReference Include="BootstrapBlazor.Region" Version="9.0.0" />
69+
<PackageReference Include="BootstrapBlazor.Region" Version="9.0.1" />
7070
<PackageReference Include="BootstrapBlazor.SignaturePad" Version="9.0.1" />
7171
<PackageReference Include="BootstrapBlazor.SmilesDrawer" Version="9.0.2" />
7272
<PackageReference Include="BootstrapBlazor.Sortable" Version="9.0.3" />

src/BootstrapBlazor.Server/Components/Samples/AutoFills.razor

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
</ItemTemplate>
2525
</AutoFill>
2626
<section ignore>
27-
<img src="@WebsiteOption.Value.GetAvatarUrl(Model1.Id)" class="shadow" style="width: 140px; margin-bottom: 1rem; border-radius: 6px;" />
28-
<EditorForm Model="@Model1" RowType="RowType.Inline" ItemsPerRow="2" />
27+
@if (Model1 != null)
28+
{
29+
<img src="@WebsiteOption.Value.GetAvatarUrl(Model1.Id)" class="shadow" style="width: 140px; margin-bottom: 1rem; border-radius: 6px;" />
30+
<EditorForm Model="@Model1" RowType="RowType.Inline" ItemsPerRow="2" />
31+
}
2932
</section>
3033
</DemoBlock>
3134

@@ -46,7 +49,10 @@
4649
</ItemTemplate>
4750
</AutoFill>
4851
<section ignore>
49-
<EditorForm Model="@Model2" RowType="RowType.Inline" ItemsPerRow="2" />
52+
@if (Model2 != null)
53+
{
54+
<EditorForm Model="@Model2" RowType="RowType.Inline" ItemsPerRow="2" />
55+
}
5056
</section>
5157
</DemoBlock>
5258

@@ -68,7 +74,10 @@
6874
</ItemTemplate>
6975
</AutoFill>
7076
<section ignore>
71-
<EditorForm Model="@Model3" RowType="RowType.Inline" ItemsPerRow="2" />
77+
@if (Model3 != null)
78+
{
79+
<EditorForm Model="@Model3" RowType="RowType.Inline" ItemsPerRow="2" />
80+
}
7281
</section>
7382
</DemoBlock>
7483

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@page "/select-city"
2+
@inject IStringLocalizer<SelectCities> Localizer
3+
4+
<h3>@Localizer["CityTitle"]</h3>
5+
6+
<h4>@Localizer["CityDescription"]</h4>
7+
8+
<PackageTips Name="BootstrapBlazor.Region" />
9+
10+
<DemoBlock Title="@Localizer["CityNormalTitle"]"
11+
Introduction="@Localizer["CityNormalIntro"]"
12+
Name="Normal">
13+
<SelectCity Value="@_value"></SelectCity>
14+
</DemoBlock>
15+
16+
<DemoBlock Title="@Localizer["CityMultipleTitle"]"
17+
Introduction="@Localizer["CityMultipleIntro"]"
18+
Name="IsMultiple">
19+
<SelectCity IsMultiple="true" Value="@_multipleValues"></SelectCity>
20+
</DemoBlock>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Server.Components.Samples;
7+
8+
/// <summary>
9+
/// 城市选择器示例
10+
/// </summary>
11+
public partial class SelectCities
12+
{
13+
private string? _value = null;
14+
15+
private string? _multipleValues = null;
16+
}

src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6-
using Longbow.SerialPorts;
76
using Microsoft.AspNetCore.Components.Routing;
87

98
namespace BootstrapBlazor.Server.Extensions;
@@ -451,12 +450,6 @@ void AddForm(DemoMenuItem item)
451450
Url = "floating-label"
452451
},
453452
new()
454-
{
455-
IsNew = true,
456-
Text = Localizer["SelectRegion"],
457-
Url = "select-region"
458-
},
459-
new()
460453
{
461454
Text = Localizer["ListGroup"],
462455
Url = "list-group"
@@ -529,6 +522,18 @@ void AddForm(DemoMenuItem item)
529522
Url = "select"
530523
},
531524
new()
525+
{
526+
IsNew = true,
527+
Text = Localizer["SelectCity"],
528+
Url = "select-city"
529+
},
530+
new()
531+
{
532+
IsNew = true,
533+
Text = Localizer["SelectRegion"],
534+
Url = "select-region"
535+
},
536+
new()
532537
{
533538
Text = Localizer["SelectObject"],
534539
Url = "select-object"

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4873,7 +4873,8 @@
48734873
"Navbar": "Navbar",
48744874
"TaskDashBoard": "TaskDashBoard",
48754875
"Dom2ImageService": "IDom2HtmlService",
4876-
"SelectRegion": "Region Selector"
4876+
"SelectRegion": "Region Selector",
4877+
"SelectCity": "City Selector"
48774878
},
48784879
"BootstrapBlazor.Server.Components.Samples.Table.TablesHeader": {
48794880
"TablesHeaderTitle": "Header grouping function",
@@ -7227,5 +7228,13 @@
72277228
"RegionDescription": "A simple region cascade selector, provide 4 levels Chinese administrative division data",
72287229
"RegionNormalTitle": "Basic usage",
72297230
"RegionNormalIntro": "Use grouping to switch the selection mode for displaying administrative areas"
7231+
},
7232+
"BootstrapBlazor.Server.Components.Samples.SelectCities": {
7233+
"CityTitle": "City Selector",
7234+
"CityDescription": "Provides a city selector classified by province",
7235+
"CityNormalTitle": "Basic usage",
7236+
"CityNormalIntro": "Select a city from the drop-down box",
7237+
"CityMultipleTitle": "Multiple",
7238+
"CityMultipleIntro": "Enable multiple selection mode by setting <code>IsMultiple</code> , and all cities will be automatically selected when clicking a province in the pop-up window."
72307239
}
72317240
}

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4873,7 +4873,8 @@
48734873
"Navbar": "导航栏 Navbar",
48744874
"TaskDashBoard": "任务管理器 TaskDashBoard",
48754875
"Dom2ImageService": "节点转图片服务 IDom2HtmlService",
4876-
"SelectRegion": "行政区域选择器 SelectRegion"
4876+
"SelectRegion": "行政区域选择器 SelectRegion",
4877+
"SelectCity": "城市选择器 SelectCity"
48774878
},
48784879
"BootstrapBlazor.Server.Components.Samples.Table.TablesHeader": {
48794880
"TablesHeaderTitle": "表头分组功能",
@@ -7223,9 +7224,17 @@
72237224
"Dom2ImageFullText": "长截图"
72247225
},
72257226
"BootstrapBlazor.Server.Components.Samples.SelectRegions": {
7226-
"RegionTitle": "Region 行政区域选择器",
7227+
"RegionTitle": "SelectRegion 行政区域选择器",
72277228
"RegionDescription": "提供 4 级行政区划选择器",
72287229
"RegionNormalTitle": "基本用法",
72297230
"RegionNormalIntro": "使用分组切换显示行政区域的选择模式"
7231+
},
7232+
"BootstrapBlazor.Server.Components.Samples.SelectCities": {
7233+
"CityTitle": "SelectCity 城市选择器",
7234+
"CityDescription": "提供以省分类的城市选择器",
7235+
"CityNormalTitle": "基本用法",
7236+
"CityNormalIntro": "通过下拉框的形式选择城市",
7237+
"CityMultipleTitle": "多选",
7238+
"CityMultipleIntro": "通过设置 <code>IsMultiple</code> 开启多选模式,点击弹窗中省份时自动选中所有城市"
72307239
}
72317240
}

src/BootstrapBlazor.Server/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@
256256
"task-board": "TaskBoard",
257257
"modbus-factory": "Modbus\\ModbusFactories",
258258
"serial-port-factory": "SerialPorts\\SerialPortFactories",
259-
"select-region": "Regions"
259+
"select-region": "SelectRegions",
260+
"select-city": "SelectCities"
260261
},
261262
"video": {
262263
"table": "BV1ap4y1x7Qn?p=1",

src/BootstrapBlazor/Components/EditorForm/EditorForm.razor

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,45 @@
33
@inherits BootstrapComponentBase
44

55
<div @attributes="AdditionalAttributes" class="@ClassString">
6-
<CascadingValue Value="@_editorItems" IsFixed="false">
7-
@FieldItems?.Invoke(Model)
8-
</CascadingValue>
9-
<CascadingValue Value="this" Name="EditorForm">
10-
<div class="form-body">
11-
@if (ShowUnsetGroupItemsOnTop)
12-
{
13-
if (UnsetGroupItems.Any())
6+
@if (Model != null)
7+
{
8+
<CascadingValue Value="@_editorItems" IsFixed="false">
9+
@FieldItems?.Invoke(Model)
10+
</CascadingValue>
11+
<CascadingValue Value="this" Name="EditorForm">
12+
<div class="form-body">
13+
@if (ShowUnsetGroupItemsOnTop)
1414
{
15-
@RenderUnsetGroupItems
15+
if (UnsetGroupItems.Any())
16+
{
17+
@RenderUnsetGroupItems
18+
}
19+
@foreach (var g in GroupItems)
20+
{
21+
@RenderGroupItems(g)
22+
}
1623
}
17-
@foreach (var g in GroupItems)
24+
else
1825
{
19-
@RenderGroupItems(g)
26+
@foreach (var g in GroupItems)
27+
{
28+
@RenderGroupItems(g)
29+
}
30+
if (UnsetGroupItems.Any())
31+
{
32+
@RenderUnsetGroupItems
33+
}
2034
}
21-
}
22-
else
35+
</div>
36+
37+
@if (Buttons != null)
2338
{
24-
@foreach (var g in GroupItems)
25-
{
26-
@RenderGroupItems(g)
27-
}
28-
if (UnsetGroupItems.Any())
29-
{
30-
@RenderUnsetGroupItems
31-
}
39+
<div class="bb-editor-footer form-footer">
40+
@Buttons
41+
</div>
3242
}
33-
</div>
34-
35-
@if (Buttons != null)
36-
{
37-
<div class="bb-editor-footer form-footer">
38-
@Buttons
39-
</div>
40-
}
41-
</CascadingValue>
43+
</CascadingValue>
44+
}
4245
</div>
4346

4447
@code

test/UnitTest/Components/EditorFormTest.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ public void CascadedEditContext_Ok()
5151
[Fact]
5252
public void Model_Error()
5353
{
54-
Assert.ThrowsAny<ArgumentNullException>(() =>
54+
var cut = Context.RenderComponent<EditorForm<Foo>>(pb =>
5555
{
56-
Context.RenderComponent<EditorForm<Foo>>(pb =>
57-
{
58-
pb.Add(a => a.Model, null);
59-
});
56+
pb.Add(a => a.Model, null);
6057
});
58+
Assert.Equal("<div class=\"bb-editor\"></div>", cut.Markup);
6159
}
6260

6361
[Fact]

0 commit comments

Comments
 (0)