Komodo / KomodoEdit

Komodo Edit is a fast and free multi-language code editor. Written in JS, Python, C++ and based on the Mozilla platform.
http://www.komodoide.com/komodo-edit
Other
2.16k stars 302 forks source link

ko/dialogs confirm() response property missused #3275

Open mjross opened 7 years ago

mjross commented 7 years ago

The documentation for the require("ko/dialogs").confirm() property response is misleading:

The default response. This button is shown as the default. Must be one of "Yes" or "No". If left empty or null the default response is "Yes".

That makes it sound as though the programmer should set the property to "Yes" or "No". Some example code illustrates the problem (note that assert() is just a simple utility function I use in all my unit-test code):

var d = require( "ko/dialogs" );

//  This works. The default button is "Cancel" and not the usual "Ok".
return_value = d.confirm( "press Enter without choosing a button", { response: "Cancel" } );
assert( return_value === false, "default button Cancel" );

//  This fails. The default button is still "Ok", not "Cancel".
return_value = d.confirm( "press Enter without choosing a button", { response: "No" } );
assert( return_value !== false, "default button No" );

More clear would be something like:

This button is shown as the default choice. It must be either "Ok" or "Cancel" if the default button labels are being used, or one of whichever custom button labels have been set. If this property is absent or left empty or null, then the default button is the "Ok" one.

Naatan commented 7 years ago

Looking at the source the logic for opts.response seems very flawed all the way through. I'll make this bug about removing that option altogether, I can't see it serving a logical purpose, and if there is one it should probably be facilitated better.

mjross commented 7 years ago

The documentation – and apparently also the code – for that option does seem quite flawed, but I do see value in having an option that can set which button is to be the default. Rather than eliminating it, it may be better to improve and clarify its functionality.