Subject: Re: bug#75171: 30.0.50; Checklist widget inside a group does not initialize correctly

From: Mauro Aranda <[email-masked]>
Date: Thu, 2 Jan 2025 10:56:26 -0300

Al Haji-Ali <[email-masked]> writes:

 > The following function creates four widgets (two radio button lists
 > and two checklists) inside a group. All lists have an initial value,
 > while the group has a nil value. Strangely, the radio buttons get
 > initialized correctly (selecting the correct button based on their
 > value), but the checkboxes do not (all boxes are unchecked regardless
 > of the value). Removing the group results in correct initialization.
 >
 > (defun widget-test ()
 >   (let ((items '((item :format "%[One%] " :value 1)
 >                  (item :format "%[Two%] " :value 2)
 >                  (item :format "%[Three%] " :value 3))))
 >     (widget-create
 >      'group
 >      (append '(radio-button-choice
 >                :inline t
 >                :format "Inline radio:\n%v\n"
 >                :value 2)
 >              items)
 >      (append '(radio-button-choice
 >                :format "Not inline radio:\n%v\n"
 >                :value 2)
 >              items)
 >      (append '(checklist
 >                :inline t
 >                :format "Inline checks:\n%v\n"
 >                :value (1 2))
 >              items)
 >      (append '(checklist
 >                :format "Not inline checks:\n%v\n"
 >                :value (1 2))
 >              items)))
 >   (widget-setup))
 >

There's no explicit :value for the group widget, so its value is nil,
and then the Widget library tries to create all four children with a nil
value.  The radio-button-choice widget differs from the checklist widget
in that the former tries to be created with a selected choice, and tries
harder than the checklist widget, which is fine with a value of nil.

That way, you see that the specified value is obeyed in
radio-button-choice but not in the checklist widget.

FTR, I'm not saying this is 100% correct.  I'm just trying to explain
how it works now.

 > If this is unintended behaviour, I managed to fix the inline version
 > of the checklists with this advice

This is intended behavior, AFAIU.  The parent can override values for
the children, and that way we can recreate widgets with new values just
by changing the values of the parent.

 > If it is intended behaviour, how can I correctly set the value of a
 > checklist? and why is there a discrepancy between radio buttons and
 > check lists?

I'm not sure if you want them inline or not, but here's a modification
to your recipe that works:

(defun widget-test ()
   (let ((items '((item :format "%[One%] " :value 1)
                  (item :format "%[Two%] " :value 2)
                  (item :format "%[Three%] " :value 3))))
     (widget-create
      'group
      :value '(2 (1 2))
      (append '(radio-button-choice
                :format "Not inline radio:\n%v\n"
                :value 2)
              items)
      (append '(checklist
                :format "Not inline checks:\n%v\n"
                :value (1 2))
              items)))
   (widget-setup))

As you can see, it's a matter of giving the correct value to the group
widget.