|
|
@ -42,10 +42,12 @@ public partial class NumberInput<NumberType> : InputBase where NumberType : INum
|
|
|
|
|
|
|
|
|
|
|
|
if (IsError)
|
|
|
|
if (IsError)
|
|
|
|
ErrorText = string.Empty;
|
|
|
|
ErrorText = string.Empty;
|
|
|
|
|
|
|
|
isValueNull = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ErrorText = "Error with step up!";
|
|
|
|
ErrorText = "Error with step up!";
|
|
|
|
|
|
|
|
isValueNull = true;
|
|
|
|
Value = default;
|
|
|
|
Value = default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -71,11 +73,13 @@ public partial class NumberInput<NumberType> : InputBase where NumberType : INum
|
|
|
|
|
|
|
|
|
|
|
|
if (IsError)
|
|
|
|
if (IsError)
|
|
|
|
ErrorText = string.Empty;
|
|
|
|
ErrorText = string.Empty;
|
|
|
|
|
|
|
|
isValueNull = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ErrorText = "Error with step down!";
|
|
|
|
ErrorText = "Error with step down!";
|
|
|
|
Value = default;
|
|
|
|
Value = default;
|
|
|
|
|
|
|
|
isValueNull = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
@ -104,7 +108,19 @@ public partial class NumberInput<NumberType> : InputBase where NumberType : INum
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string? _value;
|
|
|
|
private bool isValueNull { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool IsValueSet()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
if (Value is not null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
result= true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//private string? _value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -114,28 +130,28 @@ public partial class NumberInput<NumberType> : InputBase where NumberType : INum
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
[EditorRequired]
|
|
|
|
[EditorRequired]
|
|
|
|
public NumberType? Value
|
|
|
|
public NumberType? Value { get; set; } = default;
|
|
|
|
{
|
|
|
|
//{
|
|
|
|
get
|
|
|
|
// get
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
if (string.IsNullOrEmpty(_value))
|
|
|
|
// if (string.IsNullOrEmpty(_value))
|
|
|
|
return default;
|
|
|
|
// return default;
|
|
|
|
else
|
|
|
|
// else
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
try
|
|
|
|
// try
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
return Helper.ConvertToType<NumberType>(_value);
|
|
|
|
// return Helper.ConvertToType<NumberType>(_value);
|
|
|
|
} catch
|
|
|
|
// } catch
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
return default;
|
|
|
|
// return default;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
set
|
|
|
|
// set
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
_value = value?.ToString();
|
|
|
|
// Value = value;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Number of decimal places for Value. If set, Value is corrected when input looses focus
|
|
|
|
/// Number of decimal places for Value. If set, Value is corrected when input looses focus
|
|
|
@ -145,33 +161,48 @@ public partial class NumberInput<NumberType> : InputBase where NumberType : INum
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public int DecimalPlaces { get; set; } = 0;
|
|
|
|
public int DecimalPlaces { get; set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Value change event
|
|
|
|
/// Value change event
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public EventCallback<NumberType> ValueChanged { get; set; }
|
|
|
|
public EventCallback<NumberType?> ValueChanged { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public async Task SetValueAsync(ChangeEventArgs args)
|
|
|
|
//public async Task SetValueAsync(ChangeEventArgs args)
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// if (args.Value is not null)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// var newVal = args.Value.ToString()!;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (!newVal.Equals("0"))
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// if (newVal.ToString().Contains("-"))
|
|
|
|
|
|
|
|
// newVal = "-" + newVal.ToString().Replace("-", "");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (newVal.ToString().ToLower().Contains("e"))
|
|
|
|
|
|
|
|
// newVal = "e" + newVal.ToString().Replace("e", "");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (string.IsNullOrEmpty(newVal))
|
|
|
|
|
|
|
|
// await ValueChanged.InvokeAsync(default);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (!newVal.Equals(_value))
|
|
|
|
|
|
|
|
// await ValueChanged.InvokeAsync(Helper.ConvertToType<NumberType>(newVal));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task SetNumberValueAsync(ChangeEventArgs args)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (args.Value is not null)
|
|
|
|
if (args.Value is not null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var newVal = args.Value.ToString()!;
|
|
|
|
if (!string.IsNullOrEmpty(args.Value.ToString()))
|
|
|
|
|
|
|
|
|
|
|
|
if (!newVal.Equals("0"))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (newVal.ToString().Contains("-"))
|
|
|
|
Value = Helper.ConvertToType<NumberType>(args.Value);
|
|
|
|
newVal = "-" + newVal.ToString().Replace("-", "");
|
|
|
|
isValueNull = false;
|
|
|
|
|
|
|
|
} else
|
|
|
|
if (newVal.ToString().ToLower().Contains("e"))
|
|
|
|
{
|
|
|
|
newVal = "e" + newVal.ToString().Replace("e", "");
|
|
|
|
isValueNull = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
if (string.IsNullOrEmpty(newVal))
|
|
|
|
|
|
|
|
await ValueChanged.InvokeAsync(default);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!newVal.Equals(_value))
|
|
|
|
|
|
|
|
await ValueChanged.InvokeAsync(Helper.ConvertToType<NumberType>(newVal));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -179,7 +210,7 @@ public partial class NumberInput<NumberType> : InputBase where NumberType : INum
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (args.Value is not null)
|
|
|
|
if (args.Value is not null)
|
|
|
|
Value = AdjustDecimalPlaces(Helper.ConvertToType<NumberType>(args.Value));
|
|
|
|
Value = AdjustDecimalPlaces(Helper.ConvertToType<NumberType>(args.Value));
|
|
|
|
|
|
|
|
isValueNull = false;
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -189,53 +220,53 @@ public partial class NumberInput<NumberType> : InputBase where NumberType : INum
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public EventCallback<KeyboardEventArgs> OnKeyDown { get; set; }
|
|
|
|
public EventCallback<KeyboardEventArgs> OnKeyDown { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
private bool CheckKey(string key)
|
|
|
|
//private bool CheckKey(string key)
|
|
|
|
{
|
|
|
|
//{
|
|
|
|
bool result;
|
|
|
|
// bool result;
|
|
|
|
if (Helper.IsNumeric(key)) return true;
|
|
|
|
// if (Helper.IsNumeric(key)) return true;
|
|
|
|
switch (key.ToLower())
|
|
|
|
// switch (key.ToLower())
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
case "backspace":
|
|
|
|
// case "backspace":
|
|
|
|
case "delete":
|
|
|
|
// case "delete":
|
|
|
|
case "arrowleft":
|
|
|
|
// case "arrowleft":
|
|
|
|
case "arrowright":
|
|
|
|
// case "arrowright":
|
|
|
|
case "-":
|
|
|
|
// case "-":
|
|
|
|
//case "e":
|
|
|
|
// //case "e":
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
result = true;
|
|
|
|
// result = true;
|
|
|
|
break;
|
|
|
|
// break;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
default:
|
|
|
|
// default:
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
result = false;
|
|
|
|
// result = false;
|
|
|
|
break;
|
|
|
|
// break;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if ((key.Equals("-") || key.Equals("-")) && _value.Contains(key)) result = false;
|
|
|
|
// if ((key.Equals("-") || key.Equals("-")) && _value.Contains(key)) result = false;
|
|
|
|
return result;
|
|
|
|
// return result;
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
private bool _preventDefaultAction = true;
|
|
|
|
//private bool _preventDefaultAction = true;
|
|
|
|
public async Task ChangeValue(KeyboardEventArgs args)
|
|
|
|
//public async Task ChangeValue(KeyboardEventArgs args)
|
|
|
|
{
|
|
|
|
//{
|
|
|
|
_preventDefaultAction = true;
|
|
|
|
// _preventDefaultAction = true;
|
|
|
|
if (args is not null)
|
|
|
|
// if (args is not null)
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
var key = args.Key.ToString().ToLower();
|
|
|
|
// var key = args.Key.ToString().ToLower();
|
|
|
|
|
|
|
|
|
|
|
|
if (CheckKey(key))
|
|
|
|
// if (CheckKey(key))
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
_preventDefaultAction = false;
|
|
|
|
// _preventDefaultAction = false;
|
|
|
|
|
|
|
|
|
|
|
|
await OnKeyDown.InvokeAsync(args);
|
|
|
|
// await OnKeyDown.InvokeAsync(args);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
else
|
|
|
|
// else
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
args.Key = null;
|
|
|
|
// args.Key = null;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Method for adjusting decimal places provided with parameter
|
|
|
|
/// Method for adjusting decimal places provided with parameter
|
|
|
@ -259,8 +290,10 @@ public partial class NumberInput<NumberType> : InputBase where NumberType : INum
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task Clear()
|
|
|
|
private async Task Clear()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var val = Helper.ConvertToType<NumberType>(null);
|
|
|
|
//var val = Helper.ConvertToType<NumberType>(null);
|
|
|
|
await ValueChanged.InvokeAsync(val);
|
|
|
|
Value = default(NumberType);
|
|
|
|
|
|
|
|
isValueNull = true;
|
|
|
|
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region Lifecycle
|
|
|
|
#region Lifecycle
|
|
|
|