[studs-user] New HTML tag for checkbox
Status: Beta
Brought to you by:
mojavelinux
|
From: Greg H. <sc...@im...> - 2005-07-03 03:50:39
|
I've created a new tag for an HTML checkbox. The source is included
below. The only other change required is that you update WEB-INF/tld/
studs-html.tld to include an extra tag entity:
<tag>
<name>checkbox</name>
<tag-class>studs.taglib.html.HtmlCheckboxTag</tag-class>
</tag>
I haven't tested it heavily, but it is currently working for my
project. This was a little bit trickier to get working than the
password tag, but not much so.
In case the text below gets mangled, the source is available at
http://scsibug.com/HtmlCheckboxTag.php.txt
Thanks,
Greg Heartsfield
<?php
/* $Id: HtmlCheckboxTag.php,v 1.2 2005/07/03 02:10:52 ghphoto Exp $
*
* Copyright 2003-2005 Dan Allen, Mojavelinux.com
(dan...@mo...)
*
* This project was originally created by Dan Allen, but you are
permitted to
* use it, modify it and/or contribute to it. It has been largely
inspired by
* a handful of other open source projects and public specifications,
most
* notably Apache's Jakarta Project and Sun Microsystem's J2EE SDK.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import('studs.taglib.html.BaseInputTag');
import('studs.taglib.TagUtils');
/**
* @package studs.taglib.html
* @author Greg Heartsfield
* @author Dan Allen
*/
class HtmlCheckboxTag extends BaseInputTag
{
function renderTag()
{
if (!is_null($this->value))
{
$value = $this->value;
}
else
{
$value = htmlspecialchars(TagUtils::lookup($this-
>pageContext, c('StudsConstants::BEAN_KEY'), $this->property));
}
// Set returned value for checked box depending on
existing nomenclature
$on_value = 1;
if ($value == 'on' || $value == 'off')
{
$on_value = 'on';
}
else if ($value == 'true' || $value == 'false')
{
$on_value = 'true';
}
if (is_null($this->styleId))
{
$this->styleId = $this->property;
}
$xhtml = '<input type="checkbox" name="' . $this-
>property . '" value="' . $on_value . '"';
if ($value == '1' || $value == 'on')
{
$xhtml .= ' checked = "checked"';
}
$xhtml .= $this->renderStyleAttributes();
$xhtml .= $this->renderMetaAttributes();
$xhtml .= ' />';
return $xhtml;
}
}
?>
|