Skip to content

Commit

Permalink
Adds support for Static Forms
Browse files Browse the repository at this point in the history
  • Loading branch information
jbomhold3 committed Aug 10, 2024
1 parent 3467419 commit f17a6f2
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<BSFeedback For="() => Modal.HasFile"/>
</div>


@code {
private ModalClass Modal { get; set; } = new ModalClass();
private void OnFileChange(InputFileChangeEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<BSFeedback For="() => Modal.HasFile"/>
</div>


@code {
private ModalClass Modal { get; set; } = new ModalClass();
private void OnFileChange(InputFileChangeEventArgs e)
Expand Down
8 changes: 6 additions & 2 deletions src/BlazorStrap.V4/BlazorStrap.V4.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -14,7 +14,7 @@
<PackageProjectUrl>https://blazorstrap.io/</PackageProjectUrl>
<RepositoryUrl>https://github.com/chanan/BlazorStrap</RepositoryUrl>
<RootNamespace>BlazorStrap.V4</RootNamespace>
<PackageVersion>5.2.101</PackageVersion><!--Next Use 5.2.200-Preview1-->
<PackageVersion>5.2.102-Preview1</PackageVersion><!--Next Use 5.2.200-Preview1-->
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
Expand All @@ -25,6 +25,10 @@
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.*" />
<PackageReference Include="BlazorComponentUtilities" Version="1.7.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.*" />
<PackageReference Include="BlazorComponentUtilities" Version="1.7.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BlazorStrap\BlazorStrap.csproj" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/BlazorStrap.V4/Components/Forms/BSForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
formBuilder.AddEventPreventDefaultAttribute(8, "onreset", true);
}
formBuilder.AddAttribute(9, "ChildContent", EditFormChildContent);
formBuilder.AddAttribute(10, "FormName", FormName);
formBuilder.AddAttribute(11, "Enhance", Enhance);
formBuilder.CloseComponent();
};

Expand Down
3 changes: 3 additions & 0 deletions src/BlazorStrap.V4/Components/Forms/BSInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
builder.AddAttribute(9, "onfocus", OnFocusEvent);
builder.AddMultipleAttributes(8, AdditionalAttributes);
builder.AddAttribute(10, "multiple", IsMultipleSelect);
#if NET8_0_OR_GREATER
builder.AddAttribute(11, "name",NameAttributeValue );
#endif
if (Helper?.Id != null)
{
builder.AddAttribute(11, "id", Helper.Id);
Expand Down
3 changes: 3 additions & 0 deletions src/BlazorStrap.V4/Components/Forms/BSInputCheckbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
builder.AddAttribute(10, "id", Helper.Id);
}
builder.AddAttribute(11, "disabled", IsDisabled);
#if NET8_0_OR_GREATER
builder.AddAttribute(12, "name",NameAttributeValue );
#endif
builder.AddMultipleAttributes(13, AdditionalAttributes);
builder.AddElementReferenceCapture(14, elReference => Element = elReference);
builder.CloseElement();
Expand Down
8 changes: 6 additions & 2 deletions src/BlazorStrap.V5/BlazorStrap.V5.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -13,7 +13,7 @@
<PackageProjectUrl>https://blazorstrap.io/</PackageProjectUrl>
<RepositoryUrl>https://github.com/chanan/BlazorStrap</RepositoryUrl>
<RootNamespace>BlazorStrap.V5</RootNamespace>
<PackageVersion>5.2.101</PackageVersion><!--Next Use 5.2.200-Preview1-->
<PackageVersion>5.2.102-Preview1</PackageVersion><!--Next Use 5.2.200-Preview1-->
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
Expand All @@ -24,6 +24,10 @@
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.*" />
<PackageReference Include="BlazorComponentUtilities" Version="1.7.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net87.0' ">
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.*" />
<PackageReference Include="BlazorComponentUtilities" Version="1.7.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BlazorStrap\BlazorStrap.csproj" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/BlazorStrap.V5/Components/Forms/BSForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
formBuilder.AddEventPreventDefaultAttribute(8, "onreset", true);
}
formBuilder.AddAttribute(9, "ChildContent", EditFormChildContent);
formBuilder.AddAttribute(10, "FormName", FormName);
formBuilder.AddAttribute(11, "Enhance", Enhance);
formBuilder.CloseComponent();
};

Expand Down
3 changes: 3 additions & 0 deletions src/BlazorStrap.V5/Components/Forms/BSInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
builder.AddAttribute(9, "onfocus", OnFocusEvent);
builder.AddMultipleAttributes(8, AdditionalAttributes);
builder.AddAttribute(10, "multiple", IsMultipleSelect);
#if NET8_0_OR_GREATER
builder.AddAttribute(11, "name",NameAttributeValue );
#endif
if (Helper?.Id != null)
{
builder.AddAttribute(11, "id", Helper.Id);
Expand Down
3 changes: 3 additions & 0 deletions src/BlazorStrap.V5/Components/Forms/BSInputCheckbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
builder.AddAttribute(12, "id", id);
builder.AddMultipleAttributes(13, AdditionalAttributes);
builder.AddElementReferenceCapture(14, elReference => Element = elReference);
#if NET8_0_OR_GREATER
builder.AddAttribute(15, "name",NameAttributeValue );
#endif
builder.CloseElement();
if (IsToggle)
{
Expand Down
9 changes: 7 additions & 2 deletions src/BlazorStrap/BlazorStrap.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -13,7 +13,8 @@
<PackageProjectUrl>https://blazorstrap.io/</PackageProjectUrl>
<RepositoryUrl>https://github.com/chanan/BlazorStrap</RepositoryUrl>
<RootNamespace>BlazorStrap</RootNamespace>
<PackageVersion>5.2.101</PackageVersion><!--Next Use 5.2.200-Preview1-->
<PackageVersion>5.2.102-Preview1</PackageVersion>
<AnalysisLevel>6.0</AnalysisLevel><!--Next Use 5.2.200-Preview1-->
</PropertyGroup>

<ItemGroup>
Expand All @@ -40,4 +41,8 @@
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.*" />
<PackageReference Include="BlazorComponentUtilities" Version="1.7.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.*" />
<PackageReference Include="BlazorComponentUtilities" Version="1.7.1" />
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions src/BlazorStrap/Shared/Components/Forms/BSFormBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ namespace BlazorStrap.Shared.Components.Forms
public abstract class BSFormBase<TValue, TJustify> : BlazorStrapBase, IBSForm where TJustify : Enum
{
public event Action? OnResetEventHandler;

/// <summary>
/// If enabled, form submission is performed without fully reloading the page. This is
/// equivalent to adding <code>data-enhance</code> to the form.
///
/// This flag is only relevant in server-side rendering (SSR) scenarios. For interactive
/// rendering, the flag has no effect since there is no full-page reload on submit anyway.
/// </summary>
[Parameter] public bool Enhance { get; set; }

/// <summary>
/// Form alignment.
/// </summary>
Expand All @@ -17,6 +27,12 @@ public abstract class BSFormBase<TValue, TJustify> : BlazorStrapBase, IBSForm wh
/// </summary>
[Parameter] public EditContext? EditContext { get; set; }

/// <summary>
/// Gets or sets the form handler name. This is required for posting it to a server-side endpoint.
/// It is not used during interactive rendering.
/// </summary>
[Parameter] public string? FormName { get; set; }

/// <summary>
/// Gutters
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/BlazorStrap/Shared/Components/Forms/BSInputFileBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Web;
using System.Globalization;
using System.Linq.Expressions;

namespace BlazorStrap.Shared.Components.Forms
Expand Down Expand Up @@ -124,6 +125,7 @@ protected Task OnFileClick(MouseEventArgs e)
var filechangevent = new InputFileChangeEventArgs(Array.Empty<IBrowserFile>());
return OnFileChange(filechangevent);
}


private void DoValidation()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public abstract class BlazorStrapInputBase<TValue> : BlazorInputBase<TValue>, IB
CultureInfo @cultureInfo => BindConverter.FormatValue(@cultureInfo.Name),
DateTime @dateTimeValue => BindConverter.FormatValue(@dateTimeValue, _dateFormat, CultureInfo.InvariantCulture),
DateTimeOffset @dateTimeOffsetValue => BindConverter.FormatValue(@dateTimeOffsetValue, _dateFormat, CultureInfo.InvariantCulture),
#if NET6_0_OR_GREATER
#if NET6_0_OR_GREATER
DateOnly dateOnlyValue => BindConverter.FormatValue(dateOnlyValue, _dateFormat, CultureInfo.InvariantCulture),
TimeOnly timeOnlyValue => BindConverter.FormatValue(timeOnlyValue, _dateFormat, CultureInfo.InvariantCulture),
#endif
#endif
_ => base.FormatValueAsString(value),
};
}
Expand Down Expand Up @@ -312,4 +312,4 @@ private void Dispose()

#endregion
}
}
}
9 changes: 8 additions & 1 deletion src/BlazorStrap/Utilities/BlazorInputBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ namespace BlazorStrap.Utilities;
/// integrates with an <see cref="Microsoft.AspNetCore.Components.Forms.EditContext"/>, which must be supplied
/// as a cascading parameter.
/// </summary>

#if NET8_0
public abstract class BlazorInputBase<TValue> : InputBase<TValue>
{
}
#else
public abstract class BlazorInputBase<TValue> : ComponentBase, IDisposable
{

Expand Down Expand Up @@ -304,4 +310,5 @@ void IDisposable.Dispose()

Dispose(disposing: true);
}
}
}
#endif

0 comments on commit f17a6f2

Please sign in to comment.