Compare commits
2 Commits
4411307383
...
bd3827bb41
| Author | SHA1 | Date | |
|---|---|---|---|
| bd3827bb41 | |||
| 32cad03088 |
@@ -1,15 +1,15 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<RunAOTCompilation>true</RunAOTCompilation>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Enciphered.Blazor.UIComponents\Enciphered.Blazor.UIComponents.csproj" />
|
<ProjectReference Include="..\Enciphered.Blazor.UIComponents\Enciphered.Blazor.UIComponents.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<Target Name="TailwindBuild" BeforeTargets="Build">
|
<Target Name="TailwindBuild" BeforeTargets="Build">
|
||||||
<Exec Command="npx @tailwindcss/cli -i Styles/app.css -o wwwroot/css/app.css --minify" />
|
<Exec Command="npx @tailwindcss/cli -i Styles/app.css -o wwwroot/css/app.css --minify" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<PublishAot>true</PublishAot>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Target Name="TailwindBuild" BeforeTargets="Build">
|
<Target Name="TailwindBuild" BeforeTargets="Build">
|
||||||
@@ -12,11 +13,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<SupportedPlatform Include="browser" />
|
<SupportedPlatform Include="browser" />
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="9.0.14" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,19 +1,22 @@
|
|||||||
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
namespace Enciphered.Blazor.UIComponents.Validation;
|
namespace Enciphered.Blazor.UIComponents.Validation;
|
||||||
|
|
||||||
public static class FormModelBinder
|
public static class FormModelBinder
|
||||||
{
|
{
|
||||||
public static TModel Bind<TModel>(IFormCollection form) where TModel : new()
|
public static TModel Bind<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] TModel>(IFormCollection form) where TModel : new()
|
||||||
{
|
{
|
||||||
var model = new TModel();
|
var model = new TModel();
|
||||||
var props = typeof(TModel).GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
PropertyInfo[] props = typeof(TModel).GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||||
.Where(p => p.CanWrite);
|
|
||||||
|
|
||||||
foreach (var prop in props)
|
foreach (var prop in props)
|
||||||
{
|
{
|
||||||
|
if (!prop.CanWrite) continue;
|
||||||
|
|
||||||
var key = form.Keys.FirstOrDefault(k =>
|
var key = form.Keys.FirstOrDefault(k =>
|
||||||
string.Equals(k, prop.Name, StringComparison.OrdinalIgnoreCase));
|
string.Equals(k, prop.Name, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
@@ -17,7 +18,7 @@ public static class HtmxFormValidationExtensions
|
|||||||
return MapEndpoints(endpoints, basePath, validator, successMessage, onSuccess);
|
return MapEndpoints(endpoints, basePath, validator, successMessage, onSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RouteGroupBuilder MapFormValidation<TValidator, TModel>(
|
public static RouteGroupBuilder MapFormValidation<TValidator, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] TModel>(
|
||||||
this IEndpointRouteBuilder endpoints,
|
this IEndpointRouteBuilder endpoints,
|
||||||
string basePath,
|
string basePath,
|
||||||
Func<TModel, Task> onSuccess,
|
Func<TModel, Task> onSuccess,
|
||||||
|
|||||||
@@ -595,7 +595,7 @@ export function init() {
|
|||||||
syncValidationStyling();
|
syncValidationStyling();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('blazor:enhanced-load', () => {
|
window.Blazor.addEventListener('enhancedload', () => {
|
||||||
initComponents();
|
initComponents();
|
||||||
if (typeof htmx !== 'undefined') htmx.process(document.body);
|
if (typeof htmx !== 'undefined') htmx.process(document.body);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user