-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
301 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
@using FormBuilder.Models | ||
|
||
<RadzenPanelMenu> | ||
<RadzenPanelMenuItem Text="Add Validator" Icon="rule"> | ||
<RadzenPanelMenuItem Text="Required Validator" Icon="check" Click="() => AddValidator(ValidatorType.Required)"/> | ||
@switch (Field.Type) | ||
{ | ||
case FieldType.Text: | ||
<RadzenPanelMenuItem Text="Email Validator" Icon="mail" Click="() => AddValidator(ValidatorType.Email)"/> | ||
<RadzenPanelMenuItem Text="Length Validator" Icon="abc" Click="() => AddValidator(ValidatorType.Length)"/> | ||
break; | ||
case FieldType.NumericInt or FieldType.NumericDecimal: | ||
<RadzenPanelMenuItem Text="Numeric Range Validator" Icon="filter_1" Click="() => AddValidator(ValidatorType.NumericRange)"/> | ||
break; | ||
} | ||
</RadzenPanelMenuItem> | ||
</RadzenPanelMenu> | ||
|
||
<RadzenAccordion Multiple="true"> | ||
<Items> | ||
@foreach (var validator in Field.Validators) | ||
{ | ||
@switch (validator) | ||
{ | ||
case RequiredValidator requiredValidator: | ||
<RadzenAccordionItem Text="Required Validator" Icon="check"> | ||
<ValidatorPropertyEditor | ||
TValue="RequiredValidator" | ||
Validator="@requiredValidator" | ||
ValidatorChanged="RaiseFieldChanged"/> | ||
</RadzenAccordionItem> | ||
break; | ||
case EmailValidator emailValidator: | ||
<RadzenAccordionItem Text="Email Validator" Icon="mail"> | ||
<ValidatorPropertyEditor | ||
TValue="EmailValidator" | ||
Validator="@emailValidator" | ||
ValidatorChanged="RaiseFieldChanged"/> | ||
</RadzenAccordionItem> | ||
break; | ||
case LengthValidator lengthValidator: | ||
<RadzenAccordionItem Text="Length Validator" Icon="abc"> | ||
<ValidatorPropertyEditor | ||
TValue="LengthValidator" | ||
Validator="@lengthValidator" | ||
ValidatorChanged="RaiseFieldChanged"/> | ||
</RadzenAccordionItem> | ||
break; | ||
case NumericRangeValidator numericRangeValidator: | ||
<RadzenAccordionItem Text="Numeric Range Validator" Icon="filter_1"> | ||
<ValidatorPropertyEditor | ||
TValue="NumericRangeValidator" | ||
Validator="@numericRangeValidator" | ||
ValidatorChanged="RaiseFieldChanged"/> | ||
</RadzenAccordionItem> | ||
break; | ||
} | ||
} | ||
</Items> | ||
</RadzenAccordion> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using FormBuilder.Factories; | ||
using FormBuilder.Models; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace FormBuilder.Components; | ||
|
||
public partial class FieldValidatorsEditor : ComponentBase | ||
{ | ||
#region Parameters | ||
|
||
[Parameter, EditorRequired] | ||
public Field Field { get; set; } = default!; | ||
|
||
[Parameter] | ||
public EventCallback<Field> FieldChanged { get; set; } | ||
|
||
#endregion | ||
|
||
private void RaiseFieldChanged() | ||
{ | ||
FieldChanged.InvokeAsync(Field); | ||
} | ||
|
||
private void AddValidator(ValidatorType validatorType) | ||
{ | ||
Field.Validators.Add(ValidatorFactory.Create(validatorType)); | ||
FieldChanged.InvokeAsync(Field); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
...mponents/NumericFieldPropertyEditor.razor → ...ilder/Components/NumericFieldEditor.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
@using FormBuilder.Models | ||
@typeparam TValue where TValue : FormBuilder.Models.Validator | ||
|
||
<RadzenStack Orientation="Orientation.Vertical"> | ||
<RadzenFormField Text="Error Text"> | ||
<RadzenTextBox Value="@Validator.Text" ValueChanged="OnTextChanged"/> | ||
</RadzenFormField> | ||
<RadzenStack Orientation="Orientation.Horizontal" Gap="1rem" AlignItems="AlignItems.Center"> | ||
<RadzenLabel Text="Show as popup" Component="Validator.ShowAsPopup"/> | ||
<RadzenSwitch Name="Validator.ShowAsPopup" Value="@Validator.ShowAsPopup" ValueChanged="OnShowAsPopupChanged"/> | ||
</RadzenStack> | ||
|
||
@switch (Validator) | ||
{ | ||
case RequiredValidator requiredValidator: | ||
<RadzenStack Orientation="Orientation.Horizontal" Gap="1rem" AlignItems="AlignItems.Center"> | ||
<RadzenLabel Text="Required" Component="Validator.IsRequired"/> | ||
<RadzenSwitch Name="Validator.IsRequired" Value="@requiredValidator.IsRequired" Disabled="true"/> | ||
</RadzenStack> | ||
<RadzenStack Orientation="Orientation.Horizontal" Gap="1rem" AlignItems="AlignItems.Center"> | ||
<RadzenLabel Text="Show required hint" Component="ShowRequiredHint"/> | ||
<RadzenSwitch Name="Validator.ShowRequiredHint" Value="@requiredValidator.ShowRequiredHint" ValueChanged="OnShowRequiredHintChanged"/> | ||
</RadzenStack> | ||
break; | ||
case LengthValidator lengthValidator: | ||
<RadzenFormField Text="Min Chars Length"> | ||
<RadzenNumeric TValue="int?" Value="lengthValidator.MinLength" ValueChanged="OnMinLengthChanged"/> | ||
</RadzenFormField> | ||
<RadzenFormField Text="Max Chars Length"> | ||
<RadzenNumeric TValue="int?" Value="lengthValidator.MaxLength" ValueChanged="OnMaxLengthChanged"/> | ||
</RadzenFormField> | ||
break; | ||
case NumericRangeValidator numericRangeValidator: | ||
<RadzenFormField Text="Min"> | ||
<RadzenNumeric TValue="int" Value="numericRangeValidator.Min" ValueChanged="OnMinChanged"/> | ||
</RadzenFormField> | ||
<RadzenFormField Text="Max"> | ||
<RadzenNumeric TValue="int" Value="numericRangeValidator.Max" ValueChanged="OnMaxChanged"/> | ||
</RadzenFormField> | ||
break; | ||
} | ||
</RadzenStack> |
74 changes: 74 additions & 0 deletions
74
src/FormBuilder/Components/ValidatorPropertyEditor.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using FormBuilder.Models; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace FormBuilder.Components; | ||
|
||
public partial class ValidatorPropertyEditor<TValue> : ComponentBase where TValue : Validator | ||
{ | ||
#region Parameters | ||
|
||
[Parameter, EditorRequired] | ||
public TValue Validator { get; set; } = default!; | ||
|
||
[Parameter] | ||
public EventCallback<TValue> ValidatorChanged { get; set; } | ||
|
||
#endregion | ||
|
||
private void OnTextChanged(string value) | ||
{ | ||
Validator.Text = value; | ||
ValidatorChanged.InvokeAsync(Validator); | ||
} | ||
|
||
private void OnShowAsPopupChanged(bool value) | ||
{ | ||
Validator.ShowAsPopup = value; | ||
ValidatorChanged.InvokeAsync(Validator); | ||
} | ||
|
||
private void OnShowRequiredHintChanged(bool value) | ||
{ | ||
if (Validator is RequiredValidator requiredValidator) | ||
{ | ||
requiredValidator.ShowRequiredHint = value; | ||
ValidatorChanged.InvokeAsync(Validator); | ||
} | ||
} | ||
|
||
private void OnMinLengthChanged(int? value) | ||
{ | ||
if (Validator is LengthValidator lengthValidator) | ||
{ | ||
lengthValidator.MinLength = value; | ||
ValidatorChanged.InvokeAsync(Validator); | ||
} | ||
} | ||
|
||
private void OnMaxLengthChanged(int? value) | ||
{ | ||
if (Validator is LengthValidator lengthValidator) | ||
{ | ||
lengthValidator.MaxLength = value; | ||
ValidatorChanged.InvokeAsync(Validator); | ||
} | ||
} | ||
|
||
private void OnMinChanged(int value) | ||
{ | ||
if (Validator is NumericRangeValidator numericRangeValidator) | ||
{ | ||
numericRangeValidator.Min = value; | ||
ValidatorChanged.InvokeAsync(Validator); | ||
} | ||
} | ||
|
||
private void OnMaxChanged(int value) | ||
{ | ||
if (Validator is NumericRangeValidator numericRangeValidator) | ||
{ | ||
numericRangeValidator.Max = value; | ||
ValidatorChanged.InvokeAsync(Validator); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.