[FIXED] [2.2] NumberField.IsEmpty Always Returns False if MinValue is Set

  1. #1

    [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:
            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]
  2. #2
    Hello @ltctech,

    Thank you for reporting this issue. We will investigate.
  3. #3
    We were able to fix it in SVN trunk. The fix will be included in the next release (v2.2).

    Thank you again for the report.

Similar Threads

  1. Replies: 2
    Last Post: Feb 07, 2013, 11:40 AM
  2. Replies: 1
    Last Post: Jul 26, 2012, 1:18 PM
  3. [CLOSED] NumberField MinValue return null value
    By Aurelio in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 22, 2012, 1:10 PM
  4. [CLOSED] DateField IsEmpty always returns false
    By brettmas in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Sep 23, 2010, 1:29 AM
  5. [CLOSED] NumberField MinValue Problem
    By majestic in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 28, 2010, 3:04 PM

Posting Permissions