Spyke
August 15th, 2008, 11:03
With controls built on the default checkbox template you can add a <checked /> tag to indicate that the checkbox should be initialised in the 'on' state. However, this only works if the control is not bound to the database.
Where the checkbox has been set previously, of course, and recorded in the database, it correctly returns the previous state, but on creating a new character sheet, where the node has not yet been created, it is ignoring the <checked /> tag, and always initialising as 'off'.
To fix this, change the following fragment of code from the onInit() function in template_checkbox.lua, from:
-- Get value from source node
if sourcename then
source = window.getDatabaseNode().createChild(sourcename[1], "number");
else
source = window.getDatabaseNode().createChild(getName(), "number");
endto:
-- Get value from source node
if sourcename then
source = window.getDatabaseNode().createChild(sourcename[1], "number");
else
source = window.getDatabaseNode().createChild(getName(), "number");
if checked then
source.setValue(1);
end
end
Spyke
Where the checkbox has been set previously, of course, and recorded in the database, it correctly returns the previous state, but on creating a new character sheet, where the node has not yet been created, it is ignoring the <checked /> tag, and always initialising as 'off'.
To fix this, change the following fragment of code from the onInit() function in template_checkbox.lua, from:
-- Get value from source node
if sourcename then
source = window.getDatabaseNode().createChild(sourcename[1], "number");
else
source = window.getDatabaseNode().createChild(getName(), "number");
endto:
-- Get value from source node
if sourcename then
source = window.getDatabaseNode().createChild(sourcename[1], "number");
else
source = window.getDatabaseNode().createChild(getName(), "number");
if checked then
source.setValue(1);
end
end
Spyke