How do I get this to work in a form, on a Save-button?
<input class="button_text" type="submit" name="submit" value="Save" />
<form onsubmit="story.closeAllTiddlers();story.displayTiddler(null,'TiddlerTitle');return false;">
...
<input class="button_text" type="submit" name="submit" value="Save" />
</form> But if I can trouble You once more, I would like to implement the "toggle-group-of-tags"-funktion, as in http://www.tiddlytools.com/#DailyChecklist, into the form. Think it can be done?
I'd like to have a checkbox to toggle tag1, tag2, tag3 all at once.
I have also run in some strange problem.
It all work in my TW on my usb-stick but when I moved it (copy & paste) to the network-drive at work the script gives a error "Identifier, string or number is expected" (translated from swedish). It still work from usb-stick if I bring both up in windows next to each other but the network-copy give an error?
And if the title start or end with a blank space the tiddler vanish "The tiddler 'tiddlerTitle' doesn't yet exist. Double-click to create it". But if I open the TW in Notepad its there!
I'd like to have a checkbox to toggle tag1, tag2, tag3 all at once.Not sure what you want exactly, do you want to assign or remove a number of tags collectively? Based on what reasoning / logic? What is wrong with having multiple tag columns as in your example? Keep in mind that the tiddler you're talking about doesn't exist until you hit the submit button.
I have also run in some strange problem.It all work in my TW on my usb-stick but when I moved it (copy & paste) to the network-drive at work the script gives a error "Identifier, string or number is expected" (translated from swedish). It still work from usb-stick if I bring both up in windows next to each other but the network-copy give an error?No idea what could be wrong. At what point do you get the error, when you open the form tiddler or when you try to submit, i.e. save the TiddlyWiki?
And if the title start or end with a blank space the tiddler vanish "The tiddler 'tiddlerTitle' doesn't yet exist. Double-click to create it". But if I open the TW in Notepad its there!Well, tiddler titles shouldn't start or end with blanks, afaic. Why would they?
Just lazy I guess ;)In my example the are 6 groups with up to 12 checkboxes in every group. Often but not always a whole group or several groups have to be checked together. Would be nice to only have to click 6 times instead of 40 times :D
//make jQuery available via $
(function($){
//use a two-dimensional configuration array to define the tag categories
cats = [
[
'cat 1 title',
'cat 1 item 1 title|cat 1 item 1 tag',
'cat 1 item 2 title|cat 1 item 2 tag'
],[
'cat 2 title',
'cat 2 item 1 title|cat 2 item 1 tag',
'cat 2 item 2 title|cat 2 item 2 tag'
]
];
//first, determine the number of rows
var rows = 0;
cats.map(function(cat){
rows = Math.max(rows, cat.length);
})
var r, c, cat, $td, $tr,
$table = $('<table/>').addClass('borderless smallTable table100').appendTo(place),
$tbody = $('<tbody/>').appendTo($table),
//the function that toggles all tags for a category
toggleAll = function(){
//get the checkbox to toggle all
var $i = $(this),
//and the containing table
$table = $i.closest('table');
//get all related tag inputs and set value to that of this checkbox
$('[rel="' + $i.attr('toggle') + '"]', $table).val($i.val());
};
//loop the categories and append the tags to the table...
for(r = 0; r<rows; r++){
//add row
$tr = jQuery('<tr/>').appendTo($tbody);
//when header
if(r==0){
//add header class
$tr.addClass('table-header');
}
//loop cats
for(c==0;c< cats.length;c++){
//get category
cat = cats[c];
//when table head
if(r==0){
$td = jQuery('<td>')
.html(cat[0])
.appendto($tr);
jQuery('<input/>')
.text('all')
.attr('toggle','cat'+c)
.click(toggleAll)
.appendTo($td);
//table body
} else {
//get tag definition and split by pipe
var t = cat[r].split('|');
$td = jQuery('<td>').appendTo($tr);
jQuery('<input name ="tags[]" type="checkbox"/>')
.addClass('element checkbox')
.attr('rel','cat'+c)
.val(t[1])
.appendTo($td);
jQuery('<label/>')
.addClass('choice')
.attr('for','tags')
.text(val[0])
.appendTo($td);
}
}
};
})(jQuery);They shouldn't. It's mostly as a precation against error. The form is geared toward old, not-so-computer-savy-old-ladies ;)
//get title input
var $title = jQuery('the selector for the title input');
//set value to trimmed value, removing any blanks
$title.val($.trim($title.val());Just lazy I guess ;)
In my example the are 6 groups with up to 12 checkboxes in every group. Often but not always a whole group or several groups have to be checked together. Would be nice to only have to click 6 times instead of 40 times :DThe thing is, this does involve a bit of coding and I'm a bit reluctant to be doing and testing all that just for your special usecase. To begin with, I would certainlyconstruct the tag table using javascript, that way you can easily add the desired toggle all inputs into the table head cells programatically.
Don't bother your brain with it, a few clicks never kill anyone. It sounds easy to mess up for me ;) I will on the other hand be forever grateful if you help me with the "sanitizeing" thing. If I understode you right I put the code in the last part of the script like this:submitHandler: function(form, event) {
event.preventDefault();
var f = jQuery(form).serializeObject();
console.log("formData: ", f);var tid = new Tiddler( f.title);
tid.text = f.text;
tid.modifier = f.username;
tid.creator = f.username;
tid.tags = f.tags || [];store.saveTiddler(tid);saveChanges(true, [tid]);story.closeTiddler('formTemplate');
story.displayTiddler(null,' SenasteNytt');var $title = jQuery('title');
$title.val($.trim($title.val()));console.log("tid: ", tid)
}But I don't get it to work. Am I doing it wrong?
var $title = $("input[name=title]");
//or
var $title = $(".titleInputClass");
//or
var $title = $("#titleInputID");
var $title = $("#formID input[name=title]");
var $title = $("input[name=title]", form);
I have also run in some strange problem.It all work in my TW on my usb-stick but when I moved it (copy & paste) to the network-drive at work the script gives a error "Identifier, string or number is expected" (translated from swedish). It still work from usb-stick if I bring both up in windows next to each other but the network-copy give an error. ?
(function($){
//the code
})(jQuery); story.displayTiddler(null,'SenasteNytt'); story.displayTiddler(null,f.title);return false;