1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Fix checkbox widget to work with missing tiddlers

This commit is contained in:
Jermolene 2014-07-24 15:43:37 +01:00
parent 2a887a5bac
commit eecb9126cd

View File

@ -68,6 +68,18 @@ CheckboxWidget.prototype.getValue = function() {
return false;
}
}
} else {
if(this.checkboxTag) {
return false;
}
if(this.checkboxField) {
if(this.checkboxDefault === this.checkboxChecked) {
return true;
}
if(this.checkboxDefault === this.checkboxUnchecked) {
return false;
}
}
}
return false;
};
@ -75,12 +87,11 @@ CheckboxWidget.prototype.getValue = function() {
CheckboxWidget.prototype.handleChangeEvent = function(event) {
var checked = this.inputDomNode.checked,
tiddler = this.wiki.getTiddler(this.checkboxTitle),
newFields = {},
newFields = {title: this.checkboxTitle, text: ""},
hasChanged = false;
if(tiddler) {
// Set the tag if specified
if(this.checkboxTag && tiddler.hasTag(this.checkboxTag) !== checked) {
newFields.tags = (tiddler.fields.tags || []).slice(0);
if(this.checkboxTag && (!tiddler || tiddler.hasTag(this.checkboxTag) !== checked)) {
newFields.tags = tiddler ? (tiddler.fields.tags || []).slice(0) : [];
var pos = newFields.tags.indexOf(this.checkboxTag);
if(pos !== -1) {
newFields.tags.splice(pos,1);
@ -93,7 +104,7 @@ CheckboxWidget.prototype.handleChangeEvent = function(event) {
// Set the field if specified
if(this.checkboxField) {
var value = checked ? this.checkboxChecked : this.checkboxUnchecked;
if(tiddler.fields[this.checkboxField] !== value) {
if(!tiddler || tiddler.fields[this.checkboxField] !== value) {
newFields[this.checkboxField] = value;
hasChanged = true;
}
@ -101,7 +112,6 @@ CheckboxWidget.prototype.handleChangeEvent = function(event) {
if(hasChanged) {
this.wiki.addTiddler(new $tw.Tiddler(tiddler,newFields,this.wiki.getModificationFields()));
}
}
};
/*