8 Replies Latest reply on Mar 16, 2015 9:43 AM by disabled_jackrodgers

    Counting characters in real time

    WRossJames

      Is it possible to count the characters being entered into a field in real time? In other words, can I show a counter field that increases by one as each character is entered?

        • 1. Re: Counting characters in real time
          Stephen Huston

          You could do this with an onModify script attached to the field to be counted, and a counter field.

           

          There is some overhead and you may experience slow response as your script runs on each keystroke, but can think of no other way to do it that will update live as you type. You would also need an onEnter script on the field to count the existing length or clear the counter when entering a field to track. You may even want an onExit script for the field to clear the value when you leave the field.

          • 2. Re: Counting characters in real time
            WRossJames

            Thanks, Stephen.  I was thinking along the same lines re the onModify

            script, but hadn't thought about the need to check/reset the counter

            entering or exiting the field.

            • 3. Re: Counting characters in real time
              jbrown

              Yeah I have tried this. Its not very smooth at all.

              Too bad there's no way to c ount the number of characters.

              • 4. Re: Counting characters in real time
                Stephen Huston

                Directly counting the characters while typing (i.e. with an unstored calc) requires that the record  be committed for the "length" function to update. Committing a record on each keystroke would be problematic and visibly slower, particularly in a hosted file.

                • 5. Re: Counting characters in real time
                  brsamuel

                  What if the user were typing into a global field that is written to a "real" field on exit?  Might that speed the length() function?

                   

                  Just a thought.

                  • 6. Re: Counting characters in real time
                    Stephen Huston

                    Because the global value exits only on the local client, I am not sure what it would take to get it trigger an unstored calc to refresh, but I would still expect and Commit step to be needed. Refreshes based on globals don't always update dependant calcs even at commit unless the global is used in a relationship key or  a screen refresh is triggered. My hunch is it might even be slower, but I haven't tested this scenario in either 11 or 12.

                     

                    Might well be worth trying.

                    • 7. Re: Counting characters in real time
                      RonSmithMD

                      Hi, WRossJames.

                       

                      I thought this was an interesting question and actually it should not be a problem at all. I do something very similar with a real-time search script. I have a global field that the user is typing into and a regular listing layout where the find results are displayed. This is pretty fast actually. This table is a standard list of ICDM codes numbering about 14,000+ entries. The global field is ICD9 2::icd9_g. I pre-populate it with "Search Text Here" which is also completely highlighted. Each time I type a letter I put the cursor back at the end of the text in that global field. Now to count the letters in the field would be a simple matter of using another global field or global variable such as $$icd9_glength with a script step as

                       

                      $$icd9_glength = Length (ICD9 2::icd9_g

                       

                      at some point below the Freeze Window script step. If you are not doing a Find then this could be transparent. If you need to you could track the position of the insertion point also should it not be at the end. I don't have time right now to whip up any code to do this, but it seems trivial to me.

                       

                      Hope this helps.

                       

                       

                      If [ICD9 2::icd9_g≠ "" and ICD9 2::icd9_g ≠ "Search Text Here"]

                           Allow User Abort

                           Set Error Capture

                           Freeze Window

                           Enter Find Mode []

                           Set Field [ICD9 2::complete[]; ICD9 2::icd9_g]

                           Perform Find []

                           Sort Records

                           Set Selection [ICD9 2::icd9_g[]; Start Position: Length (ICD9 2::icd9_g) + 1; End Position: Length (ICD9 2::icd9_g) + 1]

                      Else

                           Show All Records

                      End If

                       

                       

                      Ron

                       

                      Ron Smith, MD

                      ron@ronsmithmd.com

                      • 8. Re: Counting characters in real time

                        In 13 I've used a trigger to accomplish the same thing using a global field to link to a related file and show the results in a portal.

                         

                        The global field has two triggers, one to empty the field on entry and the other to set itself to itself if modified. Forget why I did that. The relationship is set to X and a filter to show if value in a calc field is 1.

                         

                        The calc field has a LET that determines if its characters match the global field, 1 if they do.

                         

                        Gads, now I have to modify this for other tables...