Jump to content
Server Maintenance This Week. ×

About Formatted Dialog with Dynamic Buttons


This topic is 2217 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This topic is 2217 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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