DaleLong

Filter a number field entry to allow only a single period character

Discussion created by DaleLong on Jun 13, 2017
Latest reply on Jun 13, 2017 by philmodjunk

I have successfully designed a number entry field that allows only number characters and the "." character to be entered, thus mostly enforcing the entry of a valid number character. I am doing this in the following way.

 

I use an OnObjectModify script trigger on the number field, which calls a 'Refresh Field' script. A filter value is passed into the script to allow the entry of certain characters - in this case:

 

JSONFormatElements ( JSONSetElement ( "{}" ; "filter" ;  "0123456789."  ; JSONString ) )

 

The script goes as follows:

 

Set Variable [ $parameters ; Value: Get ( ScriptParameter ) ]

 

If [ not IsEmpty ( $parameters ) ]

     If [ Left ( JSONFormatElements ( $parameters ) ; 1 ) = "?" ]

          Show Custom Dialog [ "Invalid JSON" ; "blahblah" ]

          Exit Script

     End If

 

     Set Variable [ $filter ; Value: JSONGetElement ( $parameters ; "filter" ) ]

 

     If [ $filter ]

          Set Field [ Filter ( Get ( ActiveFieldContents ) ; $filter ) ]

     End If

End If

 

Set Variable [ $current_selection_start ; Value: Get ( ActiveSelectionStart ) ]

Set Variable [ $current_selection_size ; Value: Get ( ActiveSelectionSize ) ]

 

Set Field [ Get ( ActiveFieldContents ) ]

 

Set Selection [ Start Position: $current_selection_start ; End Position: $current_selection_size ]

 

 

This works great, with the exception that it doesn't trap for the user entering multiple "." characters into the field. I have made another modification to this layout, basically making the 'Save' button disappear if the user enters more than one "." - this has the desired effect of preventing the entry of an invalid number value.

 

However, it would be really slick if I could actively filter the field to prevent the entry of multiple "." characters, in the same way I'm enforcing only numeric and "." characters in the first place. Sadly, I haven't been able to figure out how to accomplish that. Anybody have any clever ideas how that might be accomplished?

Outcomes