Forum Discussion

SimonPerkins's avatar
SimonPerkins
Community Member
13 years ago

Can I prevent "NaN" from appearing in numerical entry?

Is there a way to do this?  Am using conditions to handle which numbers ARE allowed and to display an error if invalid numbers are entered.  But can't get it to stop letters etc from being entered/processed.


Hopefully I'm having a Friday moment and missing something simple

43 Replies

  • DougR's avatar
    DougR
    Community Member

    Simon --  yep, thanks, I get that for cases where treating numbers as text is sufficient.  The problem is that in many common use cases (as you mentioned earlier in the thread), there's a need to be able to process numeric entries as numbers --- ie, use numeric operators in the condition expressions for things like range checking, or to any kind of calculation. These operations require the use of numeric variables ---  then we're back to the NaN display issue.

    If there was simply a way in the conditions menus to check for "NaN" as the current "value" of  a numeric variable, then we could replace NaN with something useful and understandable by all users (such as setting it to a proper numerical reset value and/or displaying "please enter a number" as feedback in an adjacent textbox for example.

    Some solution for this is fairly essential, imo, for getting basic usability in place when numeric entries are involved.  I suppose if there's no direct workaround in SL itself, javascript could be used to check that variable for the "NaN" condition and then set other variables as needed for feedback or value reset.

  • SimonPerkins's avatar
    SimonPerkins
    Community Member

    IIRC, switching to text entry (instead of numerical) means "NaN" no longer appears.  At least I think that's the case seeing as I did this 3 months ago.  If you only want the learner to enter numbers then you can use conditions to ensure this is the case.

  • DougR's avatar
    DougR
    Community Member

    I'd like to see an answer to this as well.  If a user backspaces over the 0 or whatever value is in a numerical entry field, and then clicks outside the box or hits enter for whatever reason before making an entry, "NaN" will show up in the field, indicating there was a non-number entry attempt.  This is a bit of a usability problem in that there is no way to override this with a more user-friendly phrase like "number required" or "invalid entry" or just a default of  "0" in the case of somebody clearing/backspacing and clicking out with no entry at all.  To many non-programmer users, "NaN" is meaningless and could be very unexpected and confusing to a user.

    I tried to check for this as a condition in a trigger that would replace "NaN" with something else when it appears,  but it doesn't seem possible because the "equal to" value selector does not allow a value of "NaN" to be specified, since it's not a numeric value. And, if trying to compare it to a text variable set to "NaN" that doesn't work either because text variables are not allowed to be compared to numeric variables in the conditional expressions -- these restrictions make sense generally, but they also preclude any workarounds. .

    Has anyone found a workaround for this?

    Thanks,

    Doug

  • SimonPerkins's avatar
    SimonPerkins
    Community Member

    But if that was the case, then surely you'd have this issue when having to us numerical entry, e.g. for calcs etc.  If you still want to collect numbers but don't need to calc them then I guess you're okay.  

  • SimonPerkins's avatar
    SimonPerkins
    Community Member

    Maybe switching to text entry gives more control over "incorrect" entries?  Will try later.