Foen
July 11th, 2007, 07:17
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 underlying data state, but it is unexpected behaviour.
I have modified the template_checkbox.lua code to disable state-toggling and thought I'd post it here for info.
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)
I have modified the template_checkbox.lua code to disable state-toggling and thought I'd post it here for info.
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)