meathome
May 6th, 2010, 10:25
Hi,
I am using the default checkbox template and run into some problems.
The idea is that I have a number value under witch sime checkboxes are displayed. When the value of a checkbox is changed it either adds or substracts 5 from the value depending if its checked or unchecked.
The 3 problems I have:
1.) The onValueChanged() function of the checkbox is called when first opening the checkbox.
2.) getState always return null no matter what state the checkbox is in
3.) the checkbox value is always saved in a databasenode called the same as the checbox and as a child of the charsheet.id-xxxx node even if i set a different source
Heres my code:
<sheetnumber name="ws" source="characteristics.ws.score">
<anchored>
<to>wsframe</to>
<position>insidebottomleft</position>
<offset>18,10</offset>
<size>
<width>36</width>
<height>25</height>
</size>
</anchored>
</sheetnumber>
<checkbox name="wstrained1" source="characteristics.ws.trained1">
<anchored>
<to>ws</to>
<position>belowleft</position>
<offset>0,0</offset>
<size>
<width>12</width>
<height>12</height>
</size>
</anchored>
<script>
function onValueChanged()
if wstrained1.getState()==1 then
window.ws.setValue(window.ws.getValue()+5);
else
window.ws.setValue(window.ws.getValue()-5);
end
end
</script>
</checkbox>
What am I doing wrong? I think this should be a simple matter but I cant figure it out.
Another question: Is there a way to set the value of a numberfield without it calling onValueChanged? Because I want to reset all the checkboxes if the user enters a value into the numberfield and I dont want the resulting change in the checkboxes casue a change in the value.
I am using the default checkbox template and run into some problems.
The idea is that I have a number value under witch sime checkboxes are displayed. When the value of a checkbox is changed it either adds or substracts 5 from the value depending if its checked or unchecked.
The 3 problems I have:
1.) The onValueChanged() function of the checkbox is called when first opening the checkbox.
2.) getState always return null no matter what state the checkbox is in
3.) the checkbox value is always saved in a databasenode called the same as the checbox and as a child of the charsheet.id-xxxx node even if i set a different source
Heres my code:
<sheetnumber name="ws" source="characteristics.ws.score">
<anchored>
<to>wsframe</to>
<position>insidebottomleft</position>
<offset>18,10</offset>
<size>
<width>36</width>
<height>25</height>
</size>
</anchored>
</sheetnumber>
<checkbox name="wstrained1" source="characteristics.ws.trained1">
<anchored>
<to>ws</to>
<position>belowleft</position>
<offset>0,0</offset>
<size>
<width>12</width>
<height>12</height>
</size>
</anchored>
<script>
function onValueChanged()
if wstrained1.getState()==1 then
window.ws.setValue(window.ws.getValue()+5);
else
window.ws.setValue(window.ws.getValue()-5);
end
end
</script>
</checkbox>
What am I doing wrong? I think this should be a simple matter but I cant figure it out.
Another question: Is there a way to set the value of a numberfield without it calling onValueChanged? Because I want to reset all the checkboxes if the user enters a value into the numberfield and I dont want the resulting change in the checkboxes casue a change in the value.