PDA

View Full Version : Suggestion: static checkboxes



Foen
July 11th, 2007, 07:16
This isn't a support issue, but more of a development suggestion. Sorry if it is posted to the wrong board.

The checkbox template control is really neat, but when it is associated with static data (such as reference module content) it can still be toggled. Of course this doesn't change the data state, but is unusual behaviour.

I have modified the template_checkbox.lua code to disable state-toggling and thought I'd post it here for possible inclusion in the next release.



local sourcelessvalue = false;
local sourceenabled = true;

function setState(state)
local datavalue = 1;

if state == nil or state == false or state == 0 then
datavalue = 0;
end

if source then
if sourceenabled then
source.setValue(datavalue);
end
else
if datavalue == 0 then
sourcelessvalue = false;
else
sourcelessvalue = true;
end

update();
end
end



and



function onInit()
setIcon(stateicons[1].off[1]);

if not sourceless and window.getDatabaseNode() then
-- Get value from source node
source = window.getDatabaseNode().createChild(getName(), "number");
if source then
source.onUpdate = update;
update();
end
-- Disable control if node is static
if window.getDatabaseNode().isStatic() then
sourceenabled = false;
end
else
-- Use internal value, initialize to checked if <checked /> is specified
if checked then
sourcelessvalue = true;
update();
end
end
end


Cheers

Stuart
(Foen)