all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Marcin Borkowski <mbork@mbork.pl>
To: Yuri Khan <yuri.v.khan@gmail.com>
Cc: Po Lu <luangruo@yahoo.com>,
	Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: How to read an integer from the minibuffer
Date: Sat, 13 Nov 2021 07:59:49 +0100	[thread overview]
Message-ID: <87y25spml6.fsf@mbork.pl> (raw)
In-Reply-To: <CAP_d_8VnfQafo6a=7CN+U7zfD7g+eA+LUT38m_2oJRVfbiArDQ@mail.gmail.com>


On 2021-11-12, at 08:21, Yuri Khan <yuri.v.khan@gmail.com> wrote:

> On Thu, 11 Nov 2021 at 14:19, Marcin Borkowski <mbork@mbork.pl> wrote:
>
>> >> How do I do that?  One way would be to use `read-from-minibuffer' with
>> >> a suitable keymap, but that seems slightly low-level.  If that is the
>> >> way to go, is there a good way to set up a keymap so that nothing except
>> >> some specified characters are self-inserting?  IOW, is `suppress-keymap'
>> >> the way to go or is there some other way?
>> >
>> > Perhaps you're looking for `read-number'?
>>
>> Thanks, that is nice, but not very general.  Another value I want to
>> read is a time in the hh:mm format, for example.
>
> There are lots of examples out there of form controls trying to
> prevent the user from entering invalid data, and they demonstrate many
> things you can get wrong while implementing one.
>
> A form control for integer numbers only permits typing digits (as you
> initially asked). Now the user cannot enter -42.
>
> Okay, after a bug report and a fix, the control now permits the minus
> sign. But the control validates the entry after every keypress, so, as
> soon as the user starts typing, they are presented with an error
> message, “‘-’ is not a valid integer”. Well, duh, I just started
> typing, let me finish it!
>
> My bank’s money transfer web form’s amount field filters keypresses to
> only allow digits. One, I cannot paste a number I copied from an
> invoice opened elsewhere. Two, I cannot press Ctrl+L to activate my
> browser’s address bar, or switch to another tab with Ctrl+PgUp,
> Ctrl+PgDn, or Alt+[1…9]. Three, I can’t move my cursor if I
> inadvertently skip or mistype a digit, e.g., to correct a 1000 to
> 15000, I cannot type ‘← ← ← 5’, I have to type ‘backspace backspace
> backspace 5 0 0 0’.
>
> A license activation input box in a proprietary software installer
> wants a string of 20 semi-random letters. Since no one can reliably
> enter that in one go, it splits those 20 letters into 4 groups of 5
> and presents them as separate input boxes. As a courtesy to the user,
> as soon as 5 letters are typed in the first box, the cursor
> automatically moves to the second box. However, if you mistype the
> last of those 5 letters, Backspace does not delete it, because
> technically you’re in the second box and it’s technically empty,
> there’s nothing to delete. Also, you can’t paste the whole 20-letter
> code in one go, because the first box is limited to 5 letters.
>
> A bank money transfer is confirmed with a 4-digit code that is sent in
> an SMS message. As soon as you type the 4th digit, it goes on to
> verify the code, without you having to press Enter. However, this
> means you cannot immediately correct a mistyped 4th digit; you get a
> “verification failed” message first.
>
>
> Guideline: Perform input validation only after the user has indicated
> they are finished with data entry.

Very good points, thanks.  I am now convinced that I should just
`read-string' - it's also simpler from the coding perspective.

Thanks,

-- 
Marcin Borkowski
http://mbork.pl



  reply	other threads:[~2021-11-13  6:59 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11  4:53 How to read an integer from the minibuffer Marcin Borkowski
2021-11-11  5:11 ` Po Lu
2021-11-11  7:18   ` Marcin Borkowski
2021-11-12  7:21     ` Yuri Khan
2021-11-13  6:59       ` Marcin Borkowski [this message]
2021-11-13  8:43         ` tomas
2021-11-13  7:33       ` Jean Louis
2021-11-16  6:39         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-16  7:37           ` Yuri Khan
2021-11-16  8:00             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-11  6:27 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-11 10:25 ` Gregory Heytings
2021-11-11 10:28   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-11 11:00     ` Gregory Heytings
2021-11-11 13:20       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-11 11:17 ` Gregory Heytings
2021-11-11 13:39   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-11 14:30     ` Gregory Heytings
2021-11-12  0:28       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-12  0:37         ` Gregory Heytings
2021-11-12  0:41           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-12  0:52             ` Gregory Heytings
2021-11-12  0:57               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-12 19:05                 ` Jean Louis
2021-11-12 19:25                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-12 19:55                     ` Jean Louis
2021-11-12 21:14                       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-13  6:37                         ` Jean Louis
2021-11-16  6:21                           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-12 19:56                     ` Jean Louis
2021-11-12 20:02                     ` Jean Louis
2021-11-12 20:24                       ` tomas
2021-11-12 21:15                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-12 21:30                           ` tomas
2021-11-12 21:34                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-13  6:46                           ` Jean Louis
2021-11-13  7:32                             ` tomas
2021-11-16  6:24                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-13  6:36                         ` Jean Louis
2021-11-13  8:17                           ` tomas
2021-11-13  8:44                             ` Jean Louis
2021-11-16  6:15                               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-16  6:03                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-12  1:09               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-12  1:12                 ` Gregory Heytings
2021-11-12  3:07                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-12  6:21 ` Marcin Borkowski
2021-11-16  7:52   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-16  8:05     ` Yuri Khan
2021-11-16  9:38       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-16 11:18         ` Yuri Khan
2021-11-16 11:37           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-16 11:52             ` Yuri Khan
2021-11-16 12:00               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-16 13:10               ` Emanuel Berg via Users list for the GNU Emacs text editor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y25spml6.fsf@mbork.pl \
    --to=mbork@mbork.pl \
    --cc=help-gnu-emacs@gnu.org \
    --cc=luangruo@yahoo.com \
    --cc=yuri.v.khan@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.