Using confirm() dialog box

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
sbaden
Posts: 35
Joined: June 16th, 2009, 1:07 pm
Location: Santa Clarita, CA

I am having difficulty finding documentation for the confirm dialog box. I have a script that asks the user to select a CSV file and want the option to cancel. I would like cancel to cancel the script. Here is what I have so far:

Code: Select all

main();

function main() {
	app.beginUndoGroup("Apply CSV to Text Layers");
		
	//Alert user to select a CSV file_____________________________________________________________________________________
	var gotData = false;

	while (!gotData) {
		var csv = confirm("Please select a CSV file.");
		
		var selectFile = fileGetDialog("Please select a CSV file.", "");
		var encoded_data = '';
		if (csv == true) {
			if(selectFile == null) { //Error detection
				alert("No CSV file selected. ");
			}
			else {
				var readData = selectFile.open("r","TEXT", "????");
				if(readData) {
					var encoded_data = selectFile.read();
				}
				else { //Error detection
					alert("Problems reading csv file");
				}
			gotData = true;
			}
		}
	else {
		exit();
	}

	} //end get CSV file
	//___________________________________________________________________________________________________________	
	
}
Currently, when the confirm dialog box pops up it has buttons for "yes" and "no" which I would like to change to "cancel" and "choose." Also, no matter whether I select yes or no it does the same thing (asks the user to select a CSV file).
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

I think you're stuck with Yes/No if you're using the confirm() function.

Maybe you don't really need it as you can just see if the user cancels the fileGetDialog. Actually, using File.openDialog() is preferable as it's newer / better supported.

And your script is putting up the file dialog regardless of the result of the confirm (csv) because you aren't checking the result (csv == true) until after you call fileGetDialog().
sbaden
Posts: 35
Joined: June 16th, 2009, 1:07 pm
Location: Santa Clarita, CA

Thank you Paul. I'll check out that option.
Post Reply