Noél Dubau Posted March 31, 2018 Posted March 31, 2018 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
john renfrew Posted April 1, 2018 Posted April 1, 2018 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
john renfrew Posted April 1, 2018 Posted April 1, 2018 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
Noél Dubau Posted April 1, 2018 Author Posted April 1, 2018 Thanks for these advices ! I'll take a look to morrow and return my opinion ! Noël
Noél Dubau Posted April 2, 2018 Author Posted April 2, 2018 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now