3

I create my widget with the following code:

(widget-create 'editable-list
                   :entry-format "%i %d %v"
                   :value '("")
                   '(editable-field
                     :valid-regexp "\\(?:ftp://\\|http\\(?:s?://\\)\\|magnet:\\)"
                     :error "Url does not match supported type."
                     :value ""))

Unfortunately input validation is not working. How does one define a widget of type editable-list with validation?

4

I don't think that input validation of top-level widgets happens automatically. Neither the info manual nor the source code suggest otherwise.

Composite widgets (e.g. editable-list) automatically validate their childs upon validation, but you need to explicitly validate top-level widgets yourself before using their values.

For instance, if your form has some kind of “Apply” button, you'd iterate through all relevant input widgets in its :notify action, and validate each widget by calling its :validate property, e.g.:

(let ((unvalidated-widgets my-widgets)
      form-invalid)
  (while (and unvalidated-widgets (not form-invalid))
    (let ((widget (pop unvalidated-widgets)))
      (when (widget-apply input-field :validate)
        (setq form-invalid t)
        (message "Widget %s failed verification: %s"
                 (widget-get widget :tag)
                 (widget-get widget :error)))))
  (unless form-invalid
    ;; The form is valid, do whatever you want to do with its data
    ;; …
    ))

Where my-widgets is a list of widgets in your form.

  • Just one question, how do I get individual editable-list member widget? They are inserted/deleted automagically and I don't have any reference to them. – Łukasz Gruner Nov 8 '14 at 10:47
  • Why do you need the individual widgets? – lunaryorn Nov 8 '14 at 10:54
  • 1
    so I can (widget-apply individual-child-widget :validate) – Łukasz Gruner Nov 8 '14 at 11:20
  • 1
    No need for that. The list should automatically validate its children. – lunaryorn Nov 8 '14 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.