-------------------------------------------------------------------------------- -- Title: LWFormCheckBox.lua -- Description: Like a square peg in a round hole -- Author: Raphaël Szwarc http://alt.textdrive.com/lua/ -- Creation Date: February 1, 2005 -- Legal: Copyright (C) 2005 Raphaël Szwarc -------------------------------------------------------------------------------- -- import dependencies local LWFormInput = require( "LWFormInput" ) local LWFormHidden = require( "LWFormHidden" ) local LWStyle = require( "LWStyle" ) local LUList = require( "LUList" ) -- define the class local super = LWFormInput local self = super() function self:handleComponentKeyWithValue( aComponent, aKey, aValue ) local aDefaultKey = aKey:gsub( "%.%_$", "" ) local aMethod = self:componentMethodWithKey( aComponent, aDefaultKey ) if aMethod ~= nil then local someParameters = aComponent:context():request():parameters() if aKey == aDefaultKey and someParameters:hasKey( aDefaultKey ) == true or aKey ~= aDefaultKey and someParameters:hasKey( aDefaultKey ) == false then if aValue == "true" then aValue = true else aValue = false end aComponent:invoke( aMethod, aValue ) end end end function self:prefix() return "checkbox." end function self:type() return "checkbox" end function self:isChecked() local aValue = self:bindings():get( "isChecked" ) if aValue == nil then aValue = false end return aValue end -- method for string representation function self:toString() local aBuffer = LUList() local aStyle = LWStyle:styleWithComponent( self ) aBuffer:add( "" ) aBuffer:add( self:hidden() ) return aBuffer:join( "" ) end return self