Jump 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.

About Formatted Dialog with Dynamic Buttons

Featured Replies

Hello

If I understand well the dialog returns in a variable the value clicked (in the original sample "Whatever" or "Neat") and I can define actions according to that value.

In my database I have a lot of dialogs to create each one having 2, 3 or more choices. I wanted to register a function with 5 options... But is I don't fill all I get an error of the script ; is there a way to adapt the script to have only values filled ?

In the sample I defined the option4 as ""

Thanks for your help

test_dialog_SM.fmp12

Noel

Using ? after at least on of the final input parameters and then selecting different code based on that

 

function for ref is:

 RegisterGroovy( "FormattedDialogWithDynamicButtons( message ; title ; option1 ; option2 ; option3? ; option4? )" ; "import groovy.swing.SwingBuilder¶
¶
SwingBuilder swing = new SwingBuilder()¶
if (option4) {¶
def dialog = swing.optionPane(¶
	message:message,¶
	options:[option1, option2, option3, option4]¶
)¶
dialog.createDialog(null, title).show()¶
return dialog.getValue()¶
} else if (option3){¶
def dialog = swing.optionPane(¶
	message:message,¶
	options:[option1, option2, option3]¶
)¶
dialog.createDialog(null, title).show()¶
return dialog.getValue()¶
} else {¶
def dialog = swing.optionPane(¶
	message:message,¶
	options:[option1, option2]¶
)¶
dialog.createDialog(null, title).show()¶
return dialog.getValue()¶
}¶
" )

 

I have updated your file.. on the not_full script then you call

FormattedDialogWithDynamicButtons( "Choose a value" ; "Title" ; "1" ; "2" ; "3"  )

 

test_dialog_SM.fmp12

Your function though does not give you the correct result if someone presses ESC or closes the dialog

The buttons can be a list of button names, so here is a function that returns the button number pressed OR zero if esc

As you can see, been working code for some time now..!

 

// DynamicMessage ( fm_Title, fm_Message, fm_Buttons )
// 10_06_10_JR WORKING
// v1.2
// creates a dialog with html body and buttons from a list, captures exit values and ESC as false
// captures button pressed as numeric value so can be
// used like FM Get(LastMessage Choice)

import groovy.swing.SwingBuilder

swing = new SwingBuilder()
buttons = fm_Buttons.tokenize('\n')

int i = bnum = 0

dialog = swing.optionPane(message:fm_Message, options:(buttons))
dialog.createDialog(null, fm_Title).show()
if (dialog.getValue() == null) {
	return false
} //end if
try {
	buttons.each(){
		i++
		if (it == dialog.getValue()){
			bnum = i
		} else {
			bnum = bnum
		} //end if
	} //end each
	if (bnum > 0) {
		return bnum
	} //end if
} catch (e) {
	return e
} //end try
return false

 

  • Author

Thanks for these advices ! I'll take a look to morrow and return my opinion !

Noël

  • Author

Hello John

As you said the first proposition could return error, I tried the second and it runs fine ! In the same time a french FM user (and also member of that list) gave me a solution using list of choices (here)

Have a good week

Noël

Create an account or sign in to comment

Important Information

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

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.