Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to add text in the middle of a field with a script

Featured Replies

Hi, I have a text field that the user enters information into. I also have a series of button that inserts text into this field.

The problem is I have only been able to have it insert at the end of the field.

Does anyone have an idea how to have the insert done where the cursor is located?

Thanks,

Have your Button use

Insert Calculated Result []

  • Author

Thanks for replying.

I have been using Insert Calculated Result [].

For whatever reason, it inserts at the end instead of the location of the cursor.

Consider the SetField Script step and the functions:

Let () Middle ( ) Replace ( ) Substitute

Just a simple example...

Let([

MyField = Fieldxyz;

LengthMyfield = Length( Fieldxyz) ;

Target = "." ;

TargetPosition = Positions (MyField ; Target ; 1) ;

NewPhrase = UserField ] ;

Replace( MyField ; Target ; NewPhrase) ) >> or>>

>> or>>

Middle(MyField ; 0: TargetPosition-1 ) &

NewPhrase & " " & Middle(MyField ; TargetPosition B) LengthMyfield-TargetPosition )

You can use the functions, Position, Count, Middle and Replace to insert phrases into phrases as long as there are consistant markers for the start and end and location for where a phrase should go. Think what do I want this text to go, how do I know where the destination text starts, ends and how do I know where the target is. Be aware of the differences between Substitute (requires knowing what text is replaced) and Replace (requires knowing the exact location (characters from a certain point where repacement will occur). If a 'marker" occurs only once or all "markers" can/will be replaced, Substitute is easier to use.

The above is just off the top of my head but I think you get the idea.

Good Luck.

PS

Here is a calculation I use to insert date or reason in to stock phrases such as "Please excuse from XXX from AAA to BBB due to YYY." Where AAA and BBB are blank markers for dates and XXX and YYY are blank markers for conditions. The staff selects the appropriate phrase from the portal fills in the date/Text fields that are formatted with calender vaule list or text value list respectively then print the excuse.

Let([

OptionField = PatientNote_TotalRaw ;

BlankDateAA = PatientNote_BlankDateA ;

BlankDateBB = PatientNote_BlankDateB ;

BlankDateCC = PatientNote_BlankDateC ;

BlankTextXX = PatientNote_BlankTextX ;

BlankTextYY = PatientNote_BlankTextY ;

BlankTextZZ = PatientNote_BlankTextZ ;

FinalTextAAA = Case( (PatternCount ( OptionField ; "AAA" ) > 0) and ( IsEmpty ( BlankDateAA ) = 0) ; Substitute ( OptionField ; "AAA" ; BlankDateAA ) ; OptionField ) ;

FinalTextBBB = Case( (PatternCount ( FinalTextAAA ; "BBB" ) > 0) and ( IsEmpty ( BlankDateBB ) = 0) ; Substitute ( FinalTextAAA ; "BBB" ; BlankDateBB ) ; FinalTextAAA) ;

FinalTextCCC = Case( (PatternCount ( FinalTextBBB ; "CCC" ) > 0) and ( IsEmpty ( BlankDateCC ) = 0) ; Substitute ( FinalTextBBB ; "CCC" ; BlankDateCC ) ; FinalTextBBB ) ;

FinalTextXXX = Case( (PatternCount ( FinalTextCCC ; "XXX" ) > 0) and ( IsEmpty ( BlankTextXX ) = 0) ; Substitute ( FinalTextCCC ; "XXX" ; BlankTextXX ) ; FinalTextCCC) ;

FinalTextYYY = Case( (PatternCount ( FinalTextXXX ; "YYY" ) > 0) and ( IsEmpty ( BlankTextYY ) = 0) ; Substitute ( FinalTextXXX ; "YYY" ; BlankTextYY ) ; FinalTextXXX ) ;

FinalTextZZZ = Case( (PatternCount ( FinalTextYYY ; "ZZZ" ) > 0) and ( IsEmpty ( BlankTextZZ ) = 0) ; Substitute ( FinalTextYYY ; "ZZZ" ; BlankTextZZ ) ; FinalTextYYY ) ] ;

Case(

IsEmpty ( OptionField ) = 1 ; "" ;

FinalTextZZZ ) )

Do not select a target field and also make sure that the select entire contents is unchecked.

Insert_Text.zip

Edited by Guest
added file

I have been using Insert Calculated Result [].

For whatever reason, it inserts at the end instead of the location of the cursor.

The most likely reason is that your button is located in a portal, causing your target field to lose focus when you click the button.

  • Author

Both these statements fit the problem.

mr_vodka

Do not select a target field and also make sure that the select entire contents is unchecked.

comment

The most likely reason is that your button is located in a portal, causing your target field to lose focus when you click the button.

I will change the first.

I understand the reason for the second, but to change this definitely presents a problem.

I have included a screen capture of the layout. I hope this shows my predicament.

The black squares in the portals are the buttons for the scripts.

It would appear that I am stuck with the problem, unless I can find another way to start these scripts.

Thanks.

I am thinking about using a checkbox, and having the actual button outside the portal. This might work.

Image1.jpg

Edited by Guest
Second Thought

This is indeed a predicament, and I don't know of a really good solution for it. However, there's a way to hide the issue and make it into a "feature": instead of showing the three portals, show 3 buttons, each running the same script with a different parameter.

The script would start by storing the active selection start and size into variables, then display the entries with the chosen category and pause. After user's selection, store the selected value in another variable, hide the entries, restore the active selection to the target field, and only then insert the variable as calculated result into the field.

  • Author

Thanks for the help.

I was able make it work with the checkboxes

Image2.jpg

Edited by Guest

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.