mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2024-11-23 19:42:51 +01:00
20 lines
714 B
C#
20 lines
714 B
C#
using Microsoft.AspNetCore.Components.Forms;
|
|
|
|
namespace Phantom.Web.Components.Utils;
|
|
|
|
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" : "";
|
|
}
|
|
}
|
|
}
|