I recommend using the
:validate option (works on any widget type) or the
:valid-regexp option (for the
editable-field widget only) to reject inputs that you don't like. See section 5.5 of the Widget Library manual.
Note, however, that validation doesn't appear to happen automatically. It appears to be the case that you must explicitly use
(widget-apply widget :validate) on all of your widgets at some point. The documentation doesn't seem to state this anywhere, but I suppose it makes sense; the widget library doesn't need to make many assumptions about what you're going to do with the values the user enters, leaving that up to your own code. Since mostly the widgets are used by the customization system, it just looks like this is automatic. The
group widget will automatically validate its children when validated; using one could simplify your code.
There are, of course, a few other options. The most promising is to simply remove newlines from the value when you process the form. This is not much extra work for you, and saves the user from the cognitive overhead of remembering not to enter newlines, or of following extra directions on some fields, or of having to go back and fix up the value when they get an error. The more I consider it, the more I like this option in this case.
Another possibility, if you're really dead-set on not letting the user enter a newline at all, is to modify the keymap used while editing the value. All widgets take a
:keymap argument, and
editable-field widgets have a special keymap that remaps
<RET>. You could extend that keymap to also remap
C-j. Note however that the user could also use
C-q C-j to enter a newline, and that you don't want to completely prevent them from using
C-q; it's far too useful. This is probably more work than it's worth.