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

From: Mauro Aranda <[email-masked]>
Date: Fri, 3 Jan 2025 10:05:26 -0300

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

 > On 02/01/2025, Mauro Aranda wrote:
 >
 >> Al Haji-Ali <[email-masked]> writes:
 >> 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.
 >
 > Thanks, this makes sense. Did I miss an explanation of this issue
 > somewhere in the docs?

I don't think so.  The manual is still missing good explanations.

 >> 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.
 >
 > I was aware of this behaviour for the group, but I didn't twig the
 > consequence on a checklist.
 >
 > I have to say that I find it a bit counter-intuitive. Also the fact
 > that there is no way to set the value of a checklist without repeating
 > it in the group is somewhat awkward (certainly it will complicate my
 > implementation)

Note that you don't necessarily need to repeat it in the checklist
widget.  In my example, you only need to pass the :value in group:

(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")
              items)
      (append '(checklist
                :format "Not inline checks:\n%v\n")
              items)))
   (widget-setup))

When created, radio-button-choice will get its :value set to 2 and
checklist will get it set to (1 2).

 > and a bit inconsistent since setting the value of the
 > checklist after the group creation would override the value of the
 > group. A fix, or a some way, that would prevents the group from
 > overriding the values of the children would be useful, IMO.

 > With that being said, this issue should probably be closed as "not a 
bug".

I'd like to take some time to study this and see if there's a way to
improve the situation.