The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 26 posts ] 
Author Message
 Post subject: How to create CheckBox ?
PostPosted: Mon Sep 10, 2007 7:10 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sun Sep 09, 2007 1:59 pm
Posts: 4
Hi,

I need to create checkbox to admin one of my component. For the other types of lists (generic, radio...), I use the following :
Code:
...= JHTML::_('select.genericList',... );
...= JHTML::_('select.booleanlist', ...
 = JHTML::_('select.booleanlist',..

I haven't found the way to create checkbox ... any idea ?
Moreover, I seen in the framework a class named JHTMLSelect ? should I use it instead of the JTML::_ method ?

Thanks in advance !

Olivier ;)


Top
 Profile  
 
PostPosted: Mon Sep 10, 2007 2:03 pm 
User avatar
Joomla! Champion
Joomla! Champion

Joined: Fri Aug 12, 2005 12:47 am
Posts: 6569
You should use the JHTML::_('select', ... method instead. This will do all the dirty work of loading the JHTMLSelect class for you.

_________________
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.joomlatools.com - Joomla extensions that just work


Top
 Profile  
 
PostPosted: Tue Sep 11, 2007 6:47 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sun Sep 09, 2007 1:59 pm
Posts: 4
Thanks for the answer.
However, is there a way to create a set of checkcbox this way ?

Thanks

Olivier


Top
 Profile  
 
PostPosted: Sun Sep 16, 2007 11:59 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Sep 10, 2007 2:48 pm
Posts: 8
Did we ever get an answer on this?

I'm running into the same problem... I can't find any notes on creating a check box using the same method for select.booleanlist, select.genericlist.


Top
 Profile  
 
PostPosted: Sun Jan 06, 2008 3:03 am 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Tue Mar 28, 2006 3:05 am
Posts: 128
Location: Tijuana
did any body now how to make a checkbox?

_________________
Jorge Moises
Grupo123.Net - Creando Ideas
http://www.123Hospedaje.com


Top
 Profile  
 
PostPosted: Sun Jan 06, 2008 3:31 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Sep 10, 2007 2:48 pm
Posts: 8
I did. You can't do it the way we were thinking in this thread.

It's been a while since I did it, but you can take a look here (pardon the crudity of the site).

http://www.tristate-technology.com/

Follow the Joomla! link in the left menu.
And download the zipped component.

You can look at the code in the files.
There's also a demo of the component there, so you can see the check box in action.

I'd explain it here, but like I said, it's been a while since I created that component.


Top
 Profile  
 
PostPosted: Sun Jan 06, 2008 3:36 am 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Tue Mar 28, 2006 3:05 am
Posts: 128
Location: Tijuana
Thanks FlapJack, i am downloading the componet, i see the demo and i think i found what i looking for.

thanks i will try it

_________________
Jorge Moises
Grupo123.Net - Creando Ideas
http://www.123Hospedaje.com


Top
 Profile  
 
PostPosted: Sun Jan 06, 2008 3:37 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Sep 10, 2007 2:48 pm
Posts: 8
Happy to help! :)


Top
 Profile  
 
PostPosted: Sun Nov 30, 2008 12:52 pm 
User avatar
Joomla! Guru
Joomla! Guru

Joined: Tue Aug 30, 2005 9:18 am
Posts: 559
Location: Denmark
How about writing the solution here for everyone to see it?

_________________
http://www.toolmaster.dk - Danish Joomla Services!


Top
 Profile  
 
PostPosted: Thu Feb 05, 2009 12:39 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Thu Feb 05, 2009 12:35 pm
Posts: 3
i used this approach:

http://joomlacode.org/gf/project/joomla ... em_id=8577

greetz :geek:

---- unfortunately the file is not available for download ... so i did one:

place the following code in a file called input.php under :

\libraries\joomla\html\html

the code for the input.php ( so far for checkbox only)

Code:
<?php

class JHTMLInput
{
   /**
    * Displays a checkbox
    *
    * @static
    * @return   html
    * @since   1.5
    */

   #var $_html;

   function checkbox($name,$value)
   {
      
      $html = "<input type=\"checkbox\" name=\"" . $name . "\" value=\"" . $value . "\" />";
      
      return $html;
   }
}


#Use JHTML::_('input.checkbox', name, value)


?>


now you can use:

JHTML::_('input.checkbox', $name, $value);

to get back a checkbox in htmlcode.

greetings


Top
 Profile  
 
PostPosted: Fri Jun 05, 2009 6:18 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Dec 30, 2008 10:19 pm
Posts: 11
Anyone have the original JHTMLInput class, with all the other form objects as well?
I tried to download it from the page the link took me to.
On that page the download file link I just get error.


Top
 Profile  
 
PostPosted: Sun Aug 02, 2009 7:35 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Feb 03, 2009 4:04 am
Posts: 19
Location: Redondo Beach, CA
womd,

I've added a label to your Input.checkbox method...

as womd said, this file goes in libraries/joomla/html/html/

Code:
class JHTMLInput{

   /**
    * Displays a checkbox
    *
    * @static
    * @return html
    *
    */
   function checkbox( $name, $label, $value ){
      
      $html = '<input type="checkbox" name="' . $name . '" value="' . $value . '" id="' . $name . '" />';
      $html .= '&nbsp;<label for="' . $name . '">' . $label . '</label>';
      return $html;
   }
   
}


You can call it like this...

Code:
JHTML::_( 'input.checkbox', $name, $label, $value );


I've also attached the input.php file.


You do not have the required permissions to view the files attached to this post.

_________________
Jonathan Lackey | creative director
http://zunostudios.com


Top
 Profile  
 
PostPosted: Thu Apr 15, 2010 2:25 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Thu Jan 11, 2007 6:00 am
Posts: 205
Location: New Hampshire - United States
Another approach is to use the radio button list and replace a few portions of the HTML that generates to convert the radio buttons into check boxes:

Code:

$theradiolist = JHTML::_('select.radiolist', ...

$theradiolist = str_replace(array('radio', 'selected="selected"'), array('checkbox', 'checked="checked"'), $theradiolist);


_________________
http://www.madblanks.com - Quiz, survey, assessment, custom calculator, general purpose form extension


Top
 Profile  
 
PostPosted: Sun May 16, 2010 5:26 am 
User avatar
Joomla! Fledgling
Joomla! Fledgling

Joined: Wed Apr 14, 2010 7:46 am
Posts: 1
Location: New Delhi
The solutions given by madchris, Zuno & womd are really nice but they are hacks.

It is unfortunate that Joomla does not have a standard way through JHTML()_::(some method).

Another way that I found was:
Code:
$checked    = JHTML::_( 'grid.id', $i, $row['id'] );


This was taken from

http://docs.joomla.org/Developing_a_Mod ... _and_Links


Top
 Profile  
 
PostPosted: Sat May 29, 2010 3:17 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Thu Nov 06, 2008 8:57 pm
Posts: 2
Here's a function to display the check on the grid as a non-active element.
Code:
<?php

class JHTMLOutput
{
   /**
    * Displays a checkmark or x
    *
    * @static
    * @return   tag  an HTML image tag
    * @since   1.5
    */

   #var $_html;

   function check($value, $alt=" ", $imgY = 'tick.png', $imgX = 'publish_x.png' )
   {
        $img    = $value ? $imgY : $imgX;
        
        $tag = "<img src='images/". $img ."' border='0' alt='". $alt ."' />";
      
      return $tag;
   }
   }



#Use JHTML::_('output.check', value, alt, imageYes, imageNo)



Top
 Profile  
 
PostPosted: Mon Mar 14, 2011 7:32 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Mon Mar 14, 2011 6:20 am
Posts: 2
Hey,
How to show checkbox is checked by defaukt
I am creating a checkbox using
$checked = JHTML::_( 'grid.id', $i, $row['id'] );


Top
 Profile  
 
PostPosted: Mon Mar 14, 2011 10:07 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Mon Mar 14, 2011 9:32 pm
Posts: 2
I have similar problem. I want to change the multipleselect extra field list of K2 Add new article, with check boxes. I did something but not perfect, similar to radiolist:

in file administrator/components/com_k2/models/extrafield.php
Code:
         case 'multipleSelect':
         $output=JHTML::_('select.genericlist', $defaultValues, 'K2ExtraField_'.$extraField->id.'[]', 'multiple="multiple"', 'value', 'name',$active);
         break;

change with:
Code:
         case 'multipleSelect':
         $output=JHTML::_('select.checkboxlist', $defaultValues, 'K2ExtraField_'.$extraField->id.'[]', '', 'value', 'name',$active);
         break;


in file libraries/joomla/html/html/select.php
add:
Code:
/*custom checkbox*/
   function checkboxlist( $arr, $name, $attribs = null, $key = 'value', $text = 'text', $selected = null, $idtag = false, $translate = false )
   {
      reset( $arr );
      $html = '';

      if (is_array($attribs)) {
         $attribs = JArrayHelper::toString($attribs);
       }

      $id_text = $name;
      if ( $idtag ) {
         $id_text = $idtag;
      }

      for ($i=0, $n=count( $arr ); $i < $n; $i++ )
      {
         $k   = $arr[$i]->$key;
         $t   = $translate ? JText::_( $arr[$i]->$text ) : $arr[$i]->$text;
         $id   = ( isset($arr[$i]->id) ? @$arr[$i]->id : null);

         $extra   = '';
         $extra   .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
         if (is_array( $selected ))
         {
            foreach ($selected as $val)
            {
               $k2 = is_object( $val ) ? $val->$key : $val;
               if ($k == $k2)
               {
                  $extra .= " selected=\"selected\"";
                  break;
               }
            }
         } else {
            $extra .= ((string)$k == (string)$selected ? " checked=\"checked\"" : '');
         }
         $html .= "\n\t<input type=\"checkbox\" name=\"$name\" id=\"$id_text$k\" value=\"".$k."\"$extra $attribs />";
         $html .= "\n\t<label for=\"$id_text$k\">$t</label><br>";
      }
      $html .= "\n";
      return $html;
   }
/*end custom checkbox*/

I save the article and everything is normal.
The only problem is when I edit the artcile, I have to check every option again. :eek:
If someone can help me to solve this problem I'll be thankfull.


Top
 Profile  
 
PostPosted: Sun Mar 20, 2011 11:41 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Mon Mar 14, 2011 9:32 pm
Posts: 2
I found it:
Code:
$extra .= " selected=\"selected\"";

have to be:
Code:
$extra .= " checked=\"checked\"";


Top
 Profile  
 
PostPosted: Tue Aug 09, 2011 2:02 am 
Joomla! Intern
Joomla! Intern

Joined: Tue Aug 29, 2006 11:08 pm
Posts: 56
Has this function been added in Joomla 1.7 or the Joomla Framework?

_________________
Joomla Hosting: http://www.helpinghost.com/hosting-plan/joomla-hosting.html


Top
 Profile  
 
PostPosted: Fri Dec 16, 2011 8:54 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Dec 16, 2011 8:45 pm
Posts: 1
Not sure whether this is what others need but here is what I use for creating checkboxes: :pop
Code:
JHTML::_( 'grid.id', $i, $row->id )

(I found it in MVC component tutorial (Joomla Documentation))

You can find check all checkbox code there too but it's a little bit different from what I use:
Code:
<input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />


Hope this helps someone.


Top
 Profile  
 
PostPosted: Wed Mar 21, 2012 10:09 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Sep 19, 2006 6:04 am
Posts: 26
Location: Maniowy, Poland
How to make checkboxlist in K2 - inspired by Jordan Ivanov ;) :

It's a hack because need to modify K2 and Joomla! core files. All files are attached to this post, all changes are commented in files.

    /libraries/joomla/html/html/select.php after line 125
    /administrator/components/com_k2/models/extrafield.php&nbsp; in lines: 60, 298, 224
    /administrator/components/com_k2/views/extrafield/view.html.php in line 47
    /administrator/components/com_k2/views/extrafields/view.html.php in line 72
    /media/k2/assets/js/k2.js in line 523
    /components/com_k2/models/item.php in line 1035
    /administratorllanguage/en-GB/en-BG.com_k2.ini in line 445


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
PostPosted: Sat Mar 31, 2012 7:12 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sat Mar 31, 2012 6:46 pm
Posts: 2
woomaa wrote:
How to make checkboxlist in K2 - inspired by Jordan Ivanov ;) :

It's a hack because need to modify K2 and Joomla! core files. All files are attached to this post, all changes are commented in files.

    /libraries/joomla/html/html/select.php after line 125
    /administrator/components/com_k2/models/extrafield.php&nbsp; in lines: 60, 298, 224
    /administrator/components/com_k2/views/extrafield/view.html.php in line 47
    /administrator/components/com_k2/views/extrafields/view.html.php in line 72
    /media/k2/assets/js/k2.js in line 523
    /components/com_k2/models/item.php in line 1035
    /administratorllanguage/en-GB/en-BG.com_k2.ini in line 445


Dear friend thank you for the post, it was something i was searching for a very long time.

I did all the changes. In admin it does not show me any fields when i choose "Checkbox list". I made the changes as instructed in a clean version of K2. Do you have any idea what might gone wrong?

It might be that in the zip file you attached, does not contain the /libraries/joomla/html/html/select.php file. Can you please update the attachment?

I include screenshot.
Image

Also in K2 Item edit panel i get this -> JHtmlSelect: :checkboxlist not supported.


Top
 Profile  
 
PostPosted: Sun Apr 01, 2012 8:07 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Sep 19, 2006 6:04 am
Posts: 26
Location: Maniowy, Poland
Ups...

Updated version in attachment ;)


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
PostPosted: Mon Apr 02, 2012 9:37 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sat Mar 31, 2012 6:46 pm
Posts: 2
woomaa wrote:
Ups...

Updated version in attachment ;)


Thank you very much woomaa ! It worked like a charm in Joomla 2.5 with K2 2.5.5


Top
 Profile  
 
PostPosted: Sun Apr 22, 2012 6:04 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Feb 17, 2012 3:30 pm
Posts: 12
Thanks, woomaa!


Top
 Profile  
 
PostPosted: Thu Apr 26, 2012 5:48 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Jul 31, 2009 1:48 am
Posts: 3
Thanks, woomaa!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 26 posts ] 



Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group