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