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.

Insert calculated result from script on a different layout

Featured Replies

This one has stumped me.

 

I am writing a sort of html editor in FM 11. So I went ahead and built a set of buttons just like TinyMce and started to replicate their functionality. Using the Insert Calculated Result I can select a a section of text in a field and add the html tags at the beginning and the end of the selection depending on what button is clicked. To view the result I use a web viewer on another Tab. All good for most of it until I needed to leave the field to replicate the TinyMce functionality.

1. H1, H2, paragraph etc. come in a drop down menu in TinyMce.

2. Special characters come in a window popup in TinyMce as they are too numerous to display.

 

So my problem is that I have to leave the selection I have made in the text field in order to display the drop down selection or the popup window and then the script no longer has a reference for where to Insert its Calculated result.

 

The following example script steps work well when individual buttons are on the same layout.

 

 

Set Variable [ $start; Value:Get ( ActiveSelectionStart ) ]
Set Variable [ $size; Value:Get ( ActiveSelectionSize ) ]
Set Variable [ $content; Value:Middle ( Topics::Topic_Text_body; $start ; $size ) ]
 
Insert Calculated Result [ Let ([
$sp = Get(ScriptParameter) ;
$newContent = "<" & Get(ScriptParameter) & ">" & $content &"</" & Get(ScriptParameter) & ">" ] ;
Case (
$sp = "B" ; TextStyleAdd ( $newContent ; Bold ) ;
$sp = "I" ; TextStyleAdd ( $newContent ; Italic ) ;
$sp = "u" ; TextStyleAdd ( $newContent ; Underline ) ;
$sp = "st" ; TextStyleAdd ( $Content ; Strikethrough ) ;
$sp = "sub" ; TextStyleAdd ( $newContent ; Subscript ) ;
$sp = "sup" ; TextStyleAdd ( $newContent ; Superscript ) ;
$newContent )
) ]
 
The case function is there just to generate a bit of visual feedback on the edit Tab text field.
 
If I set the variables prior to leaving the field is there any way to go back to the text originally selected in that field or the position in that field (in the case of inserting special characters) before Inserting the Calculated Result?
If I set the variables prior to leaving the field is there any way to go back to the text originally selected

 

Have a look at the Set Selection[] script step.

  • Author

Thanks for the very fast response Comment, you beat me to it.

 

I figured it out using Set Selection[] and a script trigger.

 

For others I will try to explain.

 

For the Format drop down it needed a script trigger on exiting the text field to set the ActiveSelectionStart & ActiveSelectionSize prior to clicking on the drop down field or the focus was already lost.

 

For the Special Character popup window it did not need the above script trigger in play to work but it was there anyway so may as well use it.

 

So for each problem there needs to be two scripts in the process, the second one in each being for the resultant selection and that's where to use the Set Selection[] script step to get you back to the text field and back to the original selection of text.

 

Now two very curious things.

1. This didn't work with variables. The result was just wacky but it did work with fields and using the Set Field[] script step instead.

2. Generating the Start, Size and calculating the End (as calculation field) resulted in capturing one more character so I had to add a "-1" to the Set Selection[] script step. Could have done it in the calc instead. Didn't matter.

1. This didn't work with variables. The result was just wacky

 

 

Define "wacky". Did you use global $$variables rather than script $variables that expire as soon as the script runs out?

 

 

Thanks for the very fast response Comment, you beat me to it.

 

You posted.

  • Author

By wacky I mean the result for start size and end seemed to work, from recollection, (verified by global variables being displayed on the layout via <<$$xxx>>) but the Set Selection result would be something completely different. Tried as script then global variables and did think about the expiration issue.

 

New to Set Selection[]. I'm pretty sure I just missed something but I have had problems before using variables and have to had set some global fields instead. Again I probably just missed something then too.

 

Thanks. I'm glad I posted.

I have had problems before using variables and have to had set some global fields instead.

 

You should look into that in more depth. FWIW, I have exactly the same mechanism (set $$variables on field exit, restore selection before inserting calculated result) in a file I use very often and it works without any problems.

  • 2 weeks later...
  • Author

Back to it. I reverted from a set fields to a set global variables for this and it all works. So I must have missed something.

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.