Feb 01, 2013, 1:24 AM
[FIXED] [2.2] NumberField.IsEmpty Always Returns False if MinValue is Set
Ext.Net 2.1.1
https://examples2.ext.net/#/Form/NumberField/Overview/
Notice that when you click submit with empty NumberFields in the above sample, you get:
Age : -1.79769313486232E+308 <--- double.MinValue aka NumberField.EmptyValue, no MinValue set here
Test : 0 <--- The value zero, cause MinValue 0 was set
If you call NumberField.IsEmpty on Age NumberField, you will get true.
If you call NumberField.IsEmpty on Test NumberFeld, you will get false.
Yet both are technically empty, no text was entered into them after all.
The problem appears to be in NumberField.cs NumberField.Number and NumberField.CheckRange:
IsEmpty will now return false since the Number is no longer EmptyValue nor is it null.
I don't think this is proper functionality.
CheckRange should probably check if the input is NumberField.EmptyValue and let it pass through if it is.
Doesn't really matter much to IsEmpty as it will take either null or EmptyValue.
https://examples2.ext.net/#/Form/NumberField/Overview/
Notice that when you click submit with empty NumberFields in the above sample, you get:
Age : -1.79769313486232E+308 <--- double.MinValue aka NumberField.EmptyValue, no MinValue set here
Test : 0 <--- The value zero, cause MinValue 0 was set
If you call NumberField.IsEmpty on Age NumberField, you will get true.
If you call NumberField.IsEmpty on Test NumberFeld, you will get false.
Yet both are technically empty, no text was entered into them after all.
The problem appears to be in NumberField.cs NumberField.Number and NumberField.CheckRange:
public virtual double Number
{
get
{
return this.CheckRange(Convert.ToDouble(this.Value == null ? this.EmptyValue : this.Value));
}
set
{
this.Value = this.CheckRange(value);
}
}
protected virtual double CheckRange(double number)
{
number = this.MinValue > number ? this.MinValue : number;
return this.MaxValue < number ? this.MaxValue : number;
}
So when LoadPostData sets the Number to NumberField.EmptyValue/double.MinValue, CheckRange will go ahead and set it to NumberField.MinValue.IsEmpty will now return false since the Number is no longer EmptyValue nor is it null.
I don't think this is proper functionality.
CheckRange should probably check if the input is NumberField.EmptyValue and let it pass through if it is.
protected virtual double CheckRange(double number)
{
if (number == Convert.ToDouble(this.EmptyValue))
return number;
number = this.MinValue > number ? this.MinValue : number;
return this.MaxValue < number ? this.MaxValue : number;
}
This change also results in Value being null if the NumberField was empty on postback, possibly LoadPostData should set it to EmptyValue.Doesn't really matter much to IsEmpty as it will take either null or EmptyValue.
Last edited by Daniil; Feb 07, 2013 at 11:40 AM.
Reason: [FIXED] [2.2]