Expand my Community achievements bar.

SOLVED

Number Format Entry Question

Avatar

Level 3

I want to limit a number field to two digits.

I can do that by sizing the text field and checking "limit length to visible area" in the field properties.

Alternatively, I can set a pattern num{99}.  However, if I do this, then if someone enters an alpha character, it converts it into a zero!  This is less preferable than the first option, where if someone enters an alpha character it just beeps and won't let them enter it.

Unfortunately, using field size is not always a very convenient way to specify my field format.  For one thing, I don't use a fixed-width font, so longer fields with many numbers may not be able to be accurately limited to specific number lengths, since 11111111 takes different space than 888888888.  Also, sometimes it is easiest (for cosmetic reasons) to have the field size not determined by my desired number length.  Is there a way to both limit field length and to prevent alpha entries from being converted into zeros, without relying on the "limit length to visible area" property?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Sure there is. You can make the field a decimal field by selecting the field and then choosing 'Decimal Field' from the 'Type' dropdown at the top of the 'Field' tab in the 'Object palette. Then just below the 'Patterns' Button in that same menu, you can check the 'Limit Leading Digits' box and insert 2 in the 'Max' box, then de-select the 'Limit Trailing Digits' box.

View solution in original post

3 Replies

Avatar

Correct answer by
Former Community Member

Sure there is. You can make the field a decimal field by selecting the field and then choosing 'Decimal Field' from the 'Type' dropdown at the top of the 'Field' tab in the 'Object palette. Then just below the 'Patterns' Button in that same menu, you can check the 'Limit Leading Digits' box and insert 2 in the 'Max' box, then de-select the 'Limit Trailing Digits' box.

Avatar

Level 3

One related question...

One of my fields is a numeric prefix that relates to a fiscal year designation.  Some of those are 00, 01, 02, etc., so I need to be able to specify a pattern that will insert the leading zero if someone were to type just one numeric digit.  For instance, if they typed just "1" it would enter "01."  I don't seem to be able to do this by setting the field type to "decimal" (although that worked like a charm for the rest of my fields).

Any suggestions?

To recap:  I need to (1) limit field to two numeric characters, (2) not have the field convert a mistaken alpha entry to a zero, and (3) make sure that the value is padded with leading zeros so as to fill up the entire field.

Avatar

Former Community Member

One way to do this is to put this JavaScript into the exit event of the field and make sure the language is set to JavaScript :

if(this.rawValue == 1){this.rawValue = '01';}

if(this.rawValue == 2){this.rawValue = '02';}

if(this.rawValue == 3){this.rawValue = '03';}

if(this.rawValue == 4){this.rawValue = '04';}

if(this.rawValue == 5){this.rawValue = '05';}

if(this.rawValue == 6){this.rawValue = '06';}

if(this.rawValue == 7){this.rawValue = '07';}

if(this.rawValue == 8){this.rawValue = '08';}

if(this.rawValue == 9){this.rawValue = '09';}

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----