JFormFieldCheckboxes multi select, Possibly a bug?

78 views
Skip to first unread message

ChrisH

unread,
May 11, 2010, 10:06:42 AM5/11/10
to Joomla! CMS Development
Hi,

Checked this list and JoomlaCode project and can't find anything about
this.

I'm using JFormFieldCheckboxes in a form to allow users to multi
select options using the Checkboxes list with each box having a binary
flag value (1, 2, 4, 8...). The form then returns an array of the
values checked which is fine as I use array_sum to get the integer
value of the flags added together (stored in the db as a tinyint).

But when showing the form the JFormFieldCheckboxes only accepts one
value: ((string) $option->value == (string) $this->value)
(see line 65, joomla.form.fields.checkboxes)

Because of this it behaves like a radio list, and if you save with
more than one option, none of the checkboxes are ticked.

I propose (can do myself) that it checks to see if $this->value is an
array, and if so perform and in_array so that you can specify multiple
values. A better way would be to allow the coder to specify which key
to use in a sub array or class, much like JHtml::('select.option')

Quick two second fix (tested with Monday's nightly):

if (is_array( $this->value )) {
$checked = (in_array((string) $option->value, $this->value)) ? '
checked="checked"' : '';
} else {
$checked = ((string) $option->value == (string) $this->value) ? '
checked="checked"' : '';
}

Thanks

Chris

--
You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To post to this group, send an email to joomla-...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-cm...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-cms?hl=en-GB.

Artyom Bisyarin

unread,
May 12, 2010, 8:24:38 AM5/12/10
to joomla-...@googlegroups.com
Oh JForm, my amour.

There are many bugs in the form fields which don't used in core Joomla!
components. Thanks for pointing out on this one.
I'm going to take a look on it a bit later.

Do you have also problems with HTML-layout of this field (see attached
screenshot)?
Artyom
formfield-layout-bug.png

Chris H

unread,
May 12, 2010, 3:19:53 PM5/12/10
to joomla-...@googlegroups.com
Hi Artyom,

yer did have that problem, I added a css override for my component to
list them inline like the radio list. Can send you that as well if you
want, or including fieldset.checkboxes where the template.css defines
the radio list works just as good.

I've used the code I posted in a few forms now and still seems to work
fine. Used a class called BitArray (few versions around, used MITs
one) to split out the flag into an array containg 1,2,4,8, not sure if
other people would find that useful?

Thanks

Artyom Bisyarin

unread,
May 20, 2010, 3:00:35 PM5/20/10
to joomla-...@googlegroups.com
On Wed, 12 May 2010 22:19:53 +0300, Chris H <chris....@gmail.com>
wrote:

> Hi Artyom,
>
> yer did have that problem, I added a css override for my component to
> list them inline like the radio list. Can send you that as well if you
> want, or including fieldset.checkboxes where the template.css defines
> the radio list works just as good.
>
> I've used the code I posted in a few forms now and still seems to work
> fine. Used a class called BitArray (few versions around, used MITs
> one) to split out the flag into an array containg 1,2,4,8, not sure if
> other people would find that useful?
>
> Thanks

Thank you too and excuse me for the lull.
Could you please test new checkboxes form field in your environment? Don't
forget to remove your CSS-overrides -- new field includes them.
Depending on your taste you can use the patch or the php-file which you
can found in the attachments.

If somebody needs a clean environment for testing form fields then one can
install this component:
http://joomlacode.org/gf/project/jformtest

Have fun.
jformfield-checkboxes.diff
checkboxes.php

ChrisH

unread,
May 24, 2010, 4:59:39 AM5/24/10
to Joomla! CMS Development
Hi,

thanks for the updated checkboxes file.

Unfortunately I can't test it at the moment as the admin component it
was for has borked and won't load any of the forms, not because of
your file (with original), I think a few things have changed from the
nightly version I was coding with before.

I have another project with a similar need for the checkboxes, so I'll
make a start on its admin component tonight and get back to you.

Thanks again

Chris

On 20 May, 20:00, "Artyom Bisyarin" <arts...@ukr.net> wrote:
> On Wed, 12 May 2010 22:19:53 +0300, Chris H <chris.neww...@gmail.com>  
>  jformfield-checkboxes.diff
> 6KViewDownload
>
>  checkboxes.php
> 4KViewDownload

ChrisH

unread,
May 26, 2010, 7:33:28 PM5/26/10
to Joomla! CMS Development
Hi again,

I've had a chance to test the patch now, and can confirm it does work
in a few different forms.

Thanks loads for the fix.

Chris

On 20 May, 20:00, "Artyom Bisyarin" <arts...@ukr.net> wrote:

> On Wed, 12 May 2010 22:19:53 +0300, Chris H <chris.neww...@gmail.com>  

Artyom Bisyarin

unread,
May 27, 2010, 6:56:55 AM5/27/10
to joomla-...@googlegroups.com
On Thu, 27 May 2010 02:33:28 +0300, ChrisH <chris....@gmail.com> wrote:

> Hi again,
>
> I've had a chance to test the patch now, and can confirm it does work
> in a few different forms.
>
> Thanks loads for the fix.

Thank a lot for your assistance :-)

Dear JBS teams, I've created a tracker item for this:
http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=20668

--
Artyom

Reply all
Reply to author
Forward
0 new messages