cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Translate the entire conversation x

Converting fractions to decimals in attribute entry

avillanueva
23-Emerald I

Converting fractions to decimals in attribute entry

Related to this idea request: https://community.ptc.com/t5/Windchill-Ideas/Support-conversion-of-fractions-to-decimals-for-IBA-real-number/idi-p/1039253

I started poking in to see how this could be done. I noticed that attributes with real numbers with units have a JS validation script associated onBlur. The function is "jsca.columns.numericRenderer.validateFloatingPointWithUnit" but surprisingly, this function is defined in 5 different locations in the codebase. Not sure which one is the one called when the attribute entry is validated but it should not be too hard to narrow that down.

avillanueva_0-1761328076954.png

Digging further, this function simply takes in a regular expression and ensures that the entry matches it:

avillanueva_1-1761328156061.png

Pumping this into AI let's us know what its checking:

avillanueva_2-1761328209552.png

The regular expression [^0-9\-\,\.E] matches any single character that is not a digit, a hyphen, a comma, a period, or the uppercase letter E. 
Here is a breakdown of the expression:
[]: This is a character class, which specifies a set of characters to match. It matches any one character contained within the brackets.
^: Placed at the very beginning of a character class, this symbol negates the set. It means to match any character not in the specified list.
0-9: This is a range that matches any single digit from 0 to 9.
\-: A hyphen (-) inside a character class can indicate a range, but since it appears before or after other characters, it loses its special meaning and is treated as a literal hyphen. However, escaping it with a backslash (\) explicitly ensures it is treated as a literal character.
\,: The comma is a literal character. Escaping it with a backslash is unnecessary but harmless. It matches a single comma.
\.: A period (.) normally matches any character, but inside a character class, it is treated as a literal period. The backslash escapes it, but it still means "a literal period".
E: The uppercase letter E is a literal character and matches only the letter E. 

Actually, the function looks at the value before the first space character if it exists and ensures that the first part matches a valid number.  Simple. 

My thought would be to hook in another JS call before all this to transform the input if it encounted a "/" character in that first part, converting it to a decimal. What do you think? I can call it only if it detects a "/" otherwise pass through. Still strange there is 5 copies of this function floating around...

0 REPLIES 0
Announcements
Top Tags