cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Neo
Neo
Level VI

How to get browse to folder and select file option inside a modal window?

My following script works, but I want to have an option for browsing to the relevant folder and then selecting the relevant file (both pre-existing) adjacent to the file/folder selection fields (last 3) in my model window. Say a button saying "Browse" adjacent to the last three fields. I also need the folder/file paths to be captured in the box once they are selected by the user, replacing the default entries. How to achieve this in JSL?

Names Default to Here (1);

dlg = New Window("Please enter the following", << Modal, <<Return Result,
	Border Box(Top(20), Bottom(0), Left(20), Right(20),
		V List Box(	
					tb1=Text Box("Test Stage "),
					teb1 = Text Edit Box("CAP", <<Set Width(200)),
					teb1<< Set Hint( "CAP or RES or RF" );
					tbs17 = Text Box(""),
                    
                    tb2=Text Box("Duration"),
					teb2 = Text Edit Box("April 2023", <<Set Width(200)),
					teb2<< Set Hint( "e.g. April 2023, Dec 2024 etc" );
					tbs27 = Text Box(""),
		
		            tb3= Text Box("Specify path to file or browse to data file (should pre-exist)"),
					teb3 = Text Edit Box("$Documents\", <<Set Width(200)),
					teb3 << Set Hint ("e.g. /Tech/");
					tbs37 = Text Box(""),
		            
		            tb4= Text Box("Specify path to file or browse to data summary file (should pre-exist)"),
					teb4 = Text Edit Box("$Documents\", <<Set Width(200)),
					teb4 << Set Hint ("e.g. /Tech/");
					tbs47 = Text Box(""),
		            
		            tb5= Text Box("Report saving directory (should pre-exist)"),
					teb5 = Text Edit Box("$Documents\Report\", <<Set Width(200)),
					teb5 << Set Hint ("e.g. /Tech/");
					tbs57 = Text Box(""),
							            
					tb1<< set font style("bold");
					tb2<< set font style("bold");
					tb3<< set font style("bold");
					tb4<< set font style("bold");
					tb5<< set font style("bold");
		);         
	);	
);
TestSatge = dlg["teb1"]; Duration = dlg["teb2"]; dtPickPath = dlg["teb3"]; dt_SumCap = dlg["teb4"];  RptSavePath = dlg["teb5"];  
//Show(TestSatge);Show(Duration); Show (dtPickPath); Show (dt_SumCap); Show (RptSavePath);

If (dlg["Button"]==-1, Throw());

In addition, is it possible to have only those files visible in the folders which user browses to, which have the following wild card e.g. CAP* as selected in the TestStage field?

Finally, Is my throw () statement correct? The idea is to stop further execution if the window is close without clicking OK.

When it's too good to be true, it's neither
2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: How to get browse to folder and select file option inside a modal window?

I'm not sure if it is possible to refine prefix when using Pick File (you can set suffix though). Below is example for Browse button (has been added only to last text edit box)

Names Default To Here(1);

set_path = Expr(
	cur_teb = (this << prev sib);
	new_dir = Pick Directory(cur_teb << get text);
	If(!IsMissing(new_dir),
		cur_teb << Set Text(Convert File Path(new_dir, windows));
	);
);

dlg = New Window("Please enter the following",
	<<Modal,
	<<Return Result,
	Border Box(Top(20), Bottom(0), Left(20), Right(20),
		V List Box(
			tb1 = Text Box("Test Stage "),
			teb1 = Text Edit Box("CAP", <<Set Width(200)),
			teb1 << Set Hint("CAP or RES or RF");
			tbs17 = Text Box("");, 
			
			tb2 = Text Box("Duration"),
			teb2 = Text Edit Box("April 2023", <<Set Width(200)),
			teb2 << Set Hint("e.g. April 2023, Dec 2024 etc");
			tbs27 = Text Box("");, 
			
			tb3 = Text Box("Specify path to file or browse to data file (should pre-exist)"),
			teb3 = Text Edit Box("$Documents\", <<Set Width(200)),
			teb3 << Set Hint("e.g. /Tech/");
			tbs37 = Text Box("");, 
			
			tb4 = Text Box("Specify path to file or browse to data summary file (should pre-exist)"),
			teb4 = Text Edit Box("$Documents\", <<Set Width(200)),
			teb4 << Set Hint("e.g. /Tech/");
			tbs47 = Text Box("");, 
			
			tb5 = Text Box("Report saving directory (should pre-exist)", << set font style("bold")),
			Lineup Box(N Col(2),
				teb5 = Text Edit Box("$Documents\Report\", <<Set Width(200), << Set Hint("e.g. /Tech/")),
				Button Box("Browse", << Set Function(function({this},
					set_path;
				)))
			),
			H List Box(
				Button Box("OK"),
				Button Box("Cancel"),
			),
			tb1 << set font style("bold");
			tb2 << set font style("bold");
			tb3 << set font style("bold");
			tb4 << set font style("bold");
		)
	)
);


If(dlg["Button"] != 1,
	Throw("Not OK");
);

jthi_0-1685013140991.png

 

I would change the condition of throw to check if the button is something different than 1 -> Throw()

-Jarmo

View solution in original post

jthi
Super User

Re: How to get browse to folder and select file option inside a modal window?

I don't think you can use TestStage for filtering using Pick File. Pick File in scripting index will tell you how to limit Pick File to only JMP files

 

Names Default To Here(1);
Pick File(
	"Select JMP File",
	"$DOCUMENTS",
	{"JMP Files|cap*jmp;jsl;jrn", "All Files|*"},
	1,
	0,
	"newJmpFile.jmp"
);

The  LineUp message comes because Set Hint is in wrong place (it should be inside Text Edit Box)

jthi_0-1685018230605.png

 

Edit: Set Hint and Set Tip have different uses, so don't get them confused

-Jarmo

View solution in original post

8 REPLIES 8
jthi
Super User

Re: How to get browse to folder and select file option inside a modal window?

I'm not sure if it is possible to refine prefix when using Pick File (you can set suffix though). Below is example for Browse button (has been added only to last text edit box)

Names Default To Here(1);

set_path = Expr(
	cur_teb = (this << prev sib);
	new_dir = Pick Directory(cur_teb << get text);
	If(!IsMissing(new_dir),
		cur_teb << Set Text(Convert File Path(new_dir, windows));
	);
);

dlg = New Window("Please enter the following",
	<<Modal,
	<<Return Result,
	Border Box(Top(20), Bottom(0), Left(20), Right(20),
		V List Box(
			tb1 = Text Box("Test Stage "),
			teb1 = Text Edit Box("CAP", <<Set Width(200)),
			teb1 << Set Hint("CAP or RES or RF");
			tbs17 = Text Box("");, 
			
			tb2 = Text Box("Duration"),
			teb2 = Text Edit Box("April 2023", <<Set Width(200)),
			teb2 << Set Hint("e.g. April 2023, Dec 2024 etc");
			tbs27 = Text Box("");, 
			
			tb3 = Text Box("Specify path to file or browse to data file (should pre-exist)"),
			teb3 = Text Edit Box("$Documents\", <<Set Width(200)),
			teb3 << Set Hint("e.g. /Tech/");
			tbs37 = Text Box("");, 
			
			tb4 = Text Box("Specify path to file or browse to data summary file (should pre-exist)"),
			teb4 = Text Edit Box("$Documents\", <<Set Width(200)),
			teb4 << Set Hint("e.g. /Tech/");
			tbs47 = Text Box("");, 
			
			tb5 = Text Box("Report saving directory (should pre-exist)", << set font style("bold")),
			Lineup Box(N Col(2),
				teb5 = Text Edit Box("$Documents\Report\", <<Set Width(200), << Set Hint("e.g. /Tech/")),
				Button Box("Browse", << Set Function(function({this},
					set_path;
				)))
			),
			H List Box(
				Button Box("OK"),
				Button Box("Cancel"),
			),
			tb1 << set font style("bold");
			tb2 << set font style("bold");
			tb3 << set font style("bold");
			tb4 << set font style("bold");
		)
	)
);


If(dlg["Button"] != 1,
	Throw("Not OK");
);

jthi_0-1685013140991.png

 

I would change the condition of throw to check if the button is something different than 1 -> Throw()

-Jarmo
Neo
Neo
Level VI

Re: How to get browse to folder and select file option inside a modal window?

@jthi  Thanks your browse button works for me.

 

My third and fourth fields are not for folder pick fields but are file picks.

Both files to be picked are JMP files - first one (in third field) is called XXX_TESTSTAGE_data.jmp and the second one (in fourth field) is XXX_TESTSTAGE_cap.JMP i.e. the difference is only _data and _cap, rest remain same.  

 

How to add browse button to folder and then to files preferably with the above suffixes in the third and fourth fields in my modal window script?

When it's too good to be true, it's neither
jthi
Super User

Re: How to get browse to folder and select file option inside a modal window?

See Pick File from Scripting Index for file selection

jthi_0-1685015876258.png

It could be that the suffix is basically only file extension, so you can only limit it to .jmp unless you build your own file selector.

https://www.jmp.com/support/help/en/17.0/#page/jmp/file-functions.shtml?os=win&source=application#ww...

jthi_1-1685015979076.png

You might be able to help the user a little bit by using default file argument.

-Jarmo
Neo
Neo
Level VI

Re: How to get browse to folder and select file option inside a modal window?

@jthi Thanks. I have added Pick File and the basic functionality seems to be there in the script below.

Now how/where do I limit the file selection to just JMP files. Also is it possible to use the TestStage entry to limit/filter the number of files visible in the dialog created by Pick File?

Names Default To Here(1);
clear log ();
set_f_path = Expr(
	cur_teb = (this << prev sib);
	new_f_dir = Pick File(cur_teb << get text);
	If(!IsMissing(new_f_dir),
		cur_teb << Set Text(Convert File Path(new_f_dir, windows));
	);
);

set_path = Expr(
	cur_teb = (this << prev sib);
	new_dir = Pick Directory(cur_teb << get text);
	If(!IsMissing(new_dir),
		cur_teb << Set Text(Convert File Path(new_dir, windows));
	);
);

dlg = New Window("Please enter the following",
	<<Modal,
	<<Return Result,
	Border Box(Top(20), Bottom(0), Left(20), Right(20),
		V List Box(
			tb1 = Text Box("Test Stage "),
			teb1 = Text Edit Box("CAP", <<Set Width(200)),
			teb1 << Set Hint("CAP or RES or RF");
			tbs17 = Text Box("");, 
			
			tb2 = Text Box("Duration"),
			teb2 = Text Edit Box("April 2023", <<Set Width(200)),
			teb2 << Set Hint("e.g. April 2023, Dec 2024 etc");
			tbs27 = Text Box("");, 
			
			tb3 = Text Box("Specify path to file or browse to data file (should pre-exist)",<< set font style("bold")),
			Lineup Box(N Col(2),
			teb3 = Text Edit Box("$Documents\", <<Set Width(200)), << Set Hint("e.g. /Tech/");
			Button Box("Browse", << Set Function(function({this},
					set_f_path;
				)))
			),
			tbs37 = Text Box("");, 
			
			tb4 = Text Box("Specify path to file or browse to data summary file (should pre-exist)", << set font style("bold")),
			Lineup Box(N Col(2),
			teb4 = Text Edit Box("$Documents\", <<Set Width(200)), << Set Hint("e.g. /Tech/");
			Button Box("Browse", << Set Function(function({this},
					set_f_path;
				)))
			),
			//teb4 << Set Hint("e.g. /Tech/");
			tbs47 = Text Box("");, 
			
			tb5 = Text Box("Report saving directory (should pre-exist)", << set font style("bold")),
			Lineup Box(N Col(2),
				teb5 = Text Edit Box("$Documents\Report\", <<Set Width(200), << Set Hint("e.g. /Tech/")),
				Button Box("Browse", << Set Function(function({this},
					set_path;
				)))
			),
			
			tbs57 = Text Box("");, 
			
			H List Box(
				Button Box("OK"),
				Button Box("Cancel"),
			),
			
			tb1 << set font style("bold");
			tb2 << set font style("bold");
			//tb3 << set font style("bold");
			//tb4 << set font style("bold");
		)
	)
);

TestSatge = dlg["teb1"]; Duration = dlg["teb2"]; dtPickPath = dlg["teb3"]; dt_SumCap = dlg["teb4"];  RptSavePath = dlg["teb5"];  
Show(TestSatge);Show(Duration); Show (dtPickPath); Show (dt_SumCap); Show (RptSavePath);
If(dlg["Button"] != 1,	Throw("Will Stop Further Execution"));
When it's too good to be true, it's neither
Neo
Neo
Level VI

Re: How to get browse to folder and select file option inside a modal window?

I also get the following the log which I did not get before. hints are no longer working where I have got browse. How to fix?

Object 'LineUpBox' does not recognize the message 'Set Hint'; perhaps you mean one of these:  <<Set Height

 Update- Fixed now. Had incorrect placement of set hint previously. 

When it's too good to be true, it's neither
jthi
Super User

Re: How to get browse to folder and select file option inside a modal window?

I don't think you can use TestStage for filtering using Pick File. Pick File in scripting index will tell you how to limit Pick File to only JMP files

 

Names Default To Here(1);
Pick File(
	"Select JMP File",
	"$DOCUMENTS",
	{"JMP Files|cap*jmp;jsl;jrn", "All Files|*"},
	1,
	0,
	"newJmpFile.jmp"
);

The  LineUp message comes because Set Hint is in wrong place (it should be inside Text Edit Box)

jthi_0-1685018230605.png

 

Edit: Set Hint and Set Tip have different uses, so don't get them confused

-Jarmo
Neo
Neo
Level VI

Re: How to get browse to folder and select file option inside a modal window?

@jthi Thanks. I was wondering if the "All Files|*" could be used to filter further. If not I will proceed as is.

When it's too good to be true, it's neither
jthi
Super User

Re: How to get browse to folder and select file option inside a modal window?

It is very helpful to run examples directly from Scripting Indices run button

jthi_0-1685019290325.png

Multiple filters will give you these options:

jthi_1-1685019305974.png

I can edit that same example directly in Scripting Index

jthi_2-1685019320072.png

 and run it again to see what is different

jthi_3-1685019333230.png

and then you can reset it back to original if you want to

jthi_4-1685019352197.png

If you are testing anything more complicated I would suggest you copy-paste the example to new script window and edit it there, reduces the chances that it will get reset like might happen in Scripting Index

 

 

 

-Jarmo