How to create CheckBox ?

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
Digital Oliv
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Sun Sep 09, 2007 1:59 pm

How to create CheckBox ?

Post by Digital Oliv » Mon Sep 10, 2007 7:10 am

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: Select all

...= 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 ;)

User avatar
Jinx
Joomla! Champion
Joomla! Champion
Posts: 6508
Joined: Fri Aug 12, 2005 12:47 am
Contact:

Re: How to create CheckBox ?

Post by Jinx » Mon Sep 10, 2007 2:03 pm

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

Digital Oliv
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Sun Sep 09, 2007 1:59 pm

Re: How to create CheckBox ?

Post by Digital Oliv » Tue Sep 11, 2007 6:47 am

Thanks for the answer.
However, is there a way to create a set of checkcbox this way ?

Thanks

Olivier

FlapJack
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Mon Sep 10, 2007 2:48 pm

Re: How to create CheckBox ?

Post by FlapJack » Sun Sep 16, 2007 11:59 pm

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.

User avatar
jmoises
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 132
Joined: Tue Mar 28, 2006 3:05 am
Location: Tijuana
Contact:

Re: How to create CheckBox ?

Post by jmoises » Sun Jan 06, 2008 3:03 am

did any body now how to make a checkbox?
Jorge Moises
Grupo123.Net - Creando Ideas
http://www.123Hospedaje.com

FlapJack
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Mon Sep 10, 2007 2:48 pm

Re: How to create CheckBox ?

Post by FlapJack » Sun Jan 06, 2008 3:31 am

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.

User avatar
jmoises
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 132
Joined: Tue Mar 28, 2006 3:05 am
Location: Tijuana
Contact:

Re: How to create CheckBox ?

Post by jmoises » Sun Jan 06, 2008 3:36 am

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

FlapJack
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Mon Sep 10, 2007 2:48 pm

Re: How to create CheckBox ?

Post by FlapJack » Sun Jan 06, 2008 3:37 am

Happy to help! :)

User avatar
Kampp
Joomla! Guru
Joomla! Guru
Posts: 563
Joined: Tue Aug 30, 2005 9:18 am
Location: Denmark
Contact:

Re: How to create CheckBox ?

Post by Kampp » Sun Nov 30, 2008 12:52 pm

How about writing the solution here for everyone to see it?
http://www.toolmaster.dk - Danish Joomla Services!

womd
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Feb 05, 2009 12:35 pm

SOLUTION -> How to create CheckBox ?

Post by womd » Thu Feb 05, 2009 12:39 pm

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: Select all

<?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

marksu1000
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Tue Dec 30, 2008 10:19 pm

Re: How to create CheckBox ?

Post by marksu1000 » Fri Jun 05, 2009 6:18 pm

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.

User avatar
zuno
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Tue Feb 03, 2009 4:04 am
Location: Long Beach, California
Contact:

Re: How to create CheckBox ?

Post by zuno » Sun Aug 02, 2009 7:35 pm

womd,

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

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

Code: Select all

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: Select all

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

madchris
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 207
Joined: Thu Jan 11, 2007 6:00 am
Location: New Hampshire - United States
Contact:

Re: How to create CheckBox ?

Post by madchris » Thu Apr 15, 2010 2:25 pm

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: Select all


$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

User avatar
kabhi_iitk
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Wed Apr 14, 2010 7:46 am
Location: New Delhi

Re: How to create CheckBox ?

Post by kabhi_iitk » Sun May 16, 2010 5:26 am

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: Select all

$checked    = JHTML::_( 'grid.id', $i, $row['id'] );
This was taken from

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

jaxent
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Nov 06, 2008 8:57 pm

Re: How to create CheckBox ?

Post by jaxent » Sat May 29, 2010 3:17 pm

Here's a function to display the check on the grid as a non-active element.

Code: Select all

<?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)


madhura_d
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Mon Mar 14, 2011 6:20 am

Re: How to create CheckBox ?

Post by madhura_d » Mon Mar 14, 2011 7:32 am

Hey,
How to show checkbox is checked by defaukt
I am creating a checkbox using
$checked = JHTML::_( 'grid.id', $i, $row['id'] );

jvivanov
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Mon Mar 14, 2011 9:32 pm

Re: How to create CheckBox ?

Post by jvivanov » Mon Mar 14, 2011 10:07 pm

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: Select all

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

Code: Select all

			case 'multipleSelect':
			$output=JHTML::_('select.checkboxlist', $defaultValues, 'K2ExtraField_'.$extraField->id.'[]', '', 'value', 'name',$active);
			break;
in file libraries/joomla/html/html/select.php
add:

Code: Select all

/*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.

jvivanov
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Mon Mar 14, 2011 9:32 pm

Re: How to create CheckBox ?

Post by jvivanov » Sun Mar 20, 2011 11:41 pm

I found it:

Code: Select all

$extra .= " selected=\"selected\"";
have to be:

Code: Select all

$extra .= " checked=\"checked\"";

hplugins
Joomla! Intern
Joomla! Intern
Posts: 56
Joined: Tue Aug 29, 2006 11:08 pm
Contact:

Re: How to create CheckBox ?

Post by hplugins » Tue Aug 09, 2011 2:02 am

Has this function been added in Joomla 1.7 or the Joomla Framework?

Pius_
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Fri Dec 16, 2011 8:45 pm

Re: How to create CheckBox ?

Post by Pius_ » Fri Dec 16, 2011 8:54 pm

Not sure whether this is what others need but here is what I use for creating checkboxes: :pop

Code: Select all

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: Select all

<input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
Hope this helps someone.

User avatar
woomaa
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Tue Sep 19, 2006 6:04 am
Location: Maniowy, Poland
Contact:

Re: How to create CheckBox list in K2?

Post by woomaa » Wed Mar 21, 2012 10:09 am

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.

Digiapple
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sat Mar 31, 2012 6:46 pm

Re: How to create CheckBox list in K2?

Post by Digiapple » Sat Mar 31, 2012 7:12 pm

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.

[list]/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

[/list]
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.

User avatar
woomaa
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Tue Sep 19, 2006 6:04 am
Location: Maniowy, Poland
Contact:

Re: How to create CheckBox ?

Post by woomaa » Sun Apr 01, 2012 8:07 pm

Ups...

Updated version in attachment ;)
You do not have the required permissions to view the files attached to this post.

Digiapple
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sat Mar 31, 2012 6:46 pm

Re: How to create CheckBox ?

Post by Digiapple » Mon Apr 02, 2012 9:37 am

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

capola
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Feb 17, 2012 3:30 pm

Re: How to create CheckBox ?

Post by capola » Sun Apr 22, 2012 6:04 pm

Thanks, woomaa!

enrik
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Fri Jul 31, 2009 1:48 am

Re: How to create CheckBox ?

Post by enrik » Thu Apr 26, 2012 5:48 pm

Thanks, woomaa!


Locked

Return to “Joomla! 1.5 Coding”