1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2024-11-24 13:42:53 +01:00
Minecraft-Phantom-Panel/Server/Phantom.Server.Web.Components/Utils/BootstrapEditContext.cs

20 lines
728 B
C#

using Microsoft.AspNetCore.Components.Forms;
namespace Phantom.Server.Web.Components.Utils;
public static class BootstrapEditContext {
public static EditContext Create(object model) {
EditContext context = new EditContext(model);
context.SetFieldCssClassProvider(ClassProvider);
return context;
}
private static BootstrapFieldCssClassProvider ClassProvider { get; } = new ();
private sealed class BootstrapFieldCssClassProvider : FieldCssClassProvider {
public override string GetFieldCssClass(EditContext editContext, in FieldIdentifier fieldIdentifier) {
return editContext.GetValidationMessages(fieldIdentifier).Any() ? "is-invalid" : editContext.IsModified(fieldIdentifier) ? "is-valid" : "";
}
}
}