2022-11-25 18:14:33 +09:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2022-11-25 02:42:55 +01:00
|
|
|
using BTCPayServer.Abstractions.Form;
|
2022-11-25 18:14:33 +09:00
|
|
|
using BTCPayServer.Validation;
|
2022-11-25 02:42:55 +01:00
|
|
|
|
|
|
|
namespace BTCPayServer.Forms;
|
|
|
|
|
2023-04-04 04:01:34 +02:00
|
|
|
public class FieldValueMirror : IFormComponentProvider
|
|
|
|
{
|
|
|
|
public string View { get; } = null;
|
|
|
|
public void Validate(Form form, Field field)
|
|
|
|
{
|
|
|
|
if (form.GetFieldByFullName(field.Value) is null)
|
|
|
|
{
|
|
|
|
field.ValidationErrors = new List<string>() {$"{field.Name} requires {field.Value} to be present"};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Register(Dictionary<string, IFormComponentProvider> typeToComponentProvider)
|
|
|
|
{
|
|
|
|
typeToComponentProvider.Add("mirror", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public string GetValue(Form form, Field field)
|
|
|
|
{
|
|
|
|
return form.GetFieldByFullName(field.Value)?.Value;
|
|
|
|
}
|
|
|
|
}
|
2023-01-06 14:18:07 +01:00
|
|
|
public class HtmlInputFormProvider : FormComponentProviderBase
|
2022-11-25 02:42:55 +01:00
|
|
|
{
|
2022-11-25 18:14:33 +09:00
|
|
|
public override void Register(Dictionary<string, IFormComponentProvider> typeToComponentProvider)
|
2022-11-25 02:42:55 +01:00
|
|
|
{
|
2022-11-25 18:14:33 +09:00
|
|
|
foreach (var t in new[] {
|
2022-11-25 02:42:55 +01:00
|
|
|
"text",
|
|
|
|
"radio",
|
|
|
|
"checkbox",
|
|
|
|
"password",
|
|
|
|
"file",
|
|
|
|
"hidden",
|
|
|
|
"button",
|
|
|
|
"submit",
|
|
|
|
"color",
|
|
|
|
"date",
|
|
|
|
"datetime-local",
|
|
|
|
"month",
|
|
|
|
"week",
|
|
|
|
"time",
|
|
|
|
"email",
|
|
|
|
"image",
|
|
|
|
"number",
|
|
|
|
"range",
|
|
|
|
"search",
|
|
|
|
"url",
|
|
|
|
"tel",
|
2022-11-25 18:14:33 +09:00
|
|
|
"reset"})
|
|
|
|
typeToComponentProvider.Add(t, this);
|
2022-11-25 02:42:55 +01:00
|
|
|
}
|
2022-11-25 18:14:33 +09:00
|
|
|
public override string View => "Forms/InputElement";
|
|
|
|
|
|
|
|
public override void Validate(Form form, Field field)
|
|
|
|
{
|
|
|
|
if (field.Required)
|
|
|
|
{
|
|
|
|
ValidateField<RequiredAttribute>(field);
|
|
|
|
}
|
|
|
|
if (field.Type == "email")
|
|
|
|
{
|
|
|
|
ValidateField<MailboxAddressAttribute>(field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|