OK, now it's all working, I think. Somehow the previous property got deleted, and we're starting again. I'm not sure why, and I'm none too happy about that fact.
This shows the use of three templates:
At present, UpdateStore() fires an alert() after updating the property; this could obviously be improved, but for now it's just proof-of-concept (and not my template, so I'm not interested in messing with it).
Update 15-June-2010: You can now optionally set the default selection for each field by providing a default element in the field map. For text fields, default should be a string. For a checkbox, set it to true to pre-check the box. For radio and select inputs, set it to the index (0-based) of the item you want selected. For all field types, if you don't specify default then the field will be blank/everything unselected. Look at the code below for some examples.
Here's the source code for this page:
TEST_ShowForm{
fields: [
// pre-load the text field with the current user name
{ label: 'Name: ', field: 'name', default: user.name },
// preselect item 2 ("bottle washer")
{ type:"select", label: 'Occupation', field: 'occupation', value: [ "unemployed","engineer","bottle washer" ], default:2 },
// no pre-selection here
{ type: "radio", label: 'Sex', field: 'sex', value: [ "Male", "Female" ] },
// pre-select to "checked"
{ type: "checkbox", field:"cool", label: "this is cool", value:"cool", default:true },
// no pre-selection for the rest of these
{ type: "radio", oneperline:true, field:"Radio2", label: "Another radio style", value: [ "one", "per", "line" ] },
{ type: 'text', label: 'Location: ', field: 'location' },
{ type:'hello', label: 'THIS BREAKS', field: 'lskdjslkdjf' },
{ field: 'time', hidden: true, value: date.now }
],
button: 'Publish'
};
UpdateStore { id: 'formdata' };
var data = json.parse(page.properties['formdata'].text ?? 'null');
if(data is not list) {
"Store is either empty or has the wrong type (type is " .. typeof(data) .. ")";
} else if(#data > 0) {
tstable{
options: { zebra:true },
columns: map.keys( { (key):true foreach var row in data, var key in map.keys(row) } ),
data: list.apply(data, "$ .. { time:date.format($.time, 'MMM d, yyyy hh:mm tt') }")
};
} else
"Store contains no data.";
| location | Radio2 | name | cool | sex | occupation | time |
|---|---|---|---|---|---|---|
| neilw | unemployed | Aug 19, 2009 07:21 PM | ||||
| neilw | unemployed | Aug 19, 2009 07:24 PM | ||||
| NJ | line | neilw | cool | Male | bottle washer | Aug 19, 2009 07:31 PM |
| sss | per | labben2004 | cool | Male | unemployed | Aug 21, 2009 12:06 PM |
| Daves | per | Dave | cool | Male | engineer | Aug 24, 2009 07:44 PM |
| Am | line | gouwzee | cool | Male | engineer | Aug 24, 2009 08:50 PM |
| ss | one | mwooscc | cool | Male | unemployed | Aug 24, 2009 09:19 PM |
| Texas | per | jraich | cool | Male | engineer | Aug 24, 2009 09:29 PM |
| UK | one | cgarcia | Male | engineer | Aug 25, 2009 07:46 AM | |
| New Zealand | zippgunn | cool | Male | engineer | Aug 27, 2009 09:33 AM | |
| Kiel | per | baum | cool | Male | engineer | Sep 1, 2009 09:54 AM |
| here | one | me | cool | Male | bottle washer | Sep 1, 2009 03:43 PM |
| here | per | sean | Male | engineer | Sep 17, 2009 01:20 PM | |
| one | sean | cool | Male | bottle washer | Sep 23, 2009 02:16 PM | |
| tampopo | line | imattdotnet | cool | Male | bottle washer | Sep 25, 2009 08:11 PM |
| tampopo | line | imattdotnet | cool | Male | bottle washer | Sep 25, 2009 08:11 PM |
| Bluefield | per | Glen | cool | Male | bottle washer | Oct 3, 2009 04:24 PM |
| fgfgs | line | jonver | cool | Female | engineer | Oct 26, 2009 06:52 PM |
| torino | per | giulio | cool | Male | unemployed | Oct 27, 2009 06:02 PM |
| zuruz | per | cptregedit | cool | Male | engineer | Dec 18, 2009 03:21 PM |
| CA | per | Cuzz' | cool | Male | bottle washer | Jan 14, 2010 11:48 PM |
| per | Anonymous | cool | Male | unemployed | Jan 30, 2010 11:38 PM | |
| there | per | kevans@7ticks.com | cool | Male | engineer | Feb 18, 2010 01:24 AM |
| Here | per | Testing | cool | Male | bottle washer | Feb 18, 2010 09:30 AM |
| Here | per | Testing | cool | Male | bottle washer | Feb 18, 2010 09:30 AM |
| London | one | waveydavey | cool | Male | engineer | Feb 26, 2010 02:44 PM |
| asasas | one | Test | cool | Male | unemployed | Mar 5, 2010 08:46 AM |
| Hamburg | one | Test | cool | Male | unemployed | Mar 5, 2010 08:47 AM |
| r | per | ter | cool | Male | bottle washer | Mar 8, 2010 01:26 PM |
| hamburg | line | SeGo | cool | Male | unemployed | Mar 8, 2010 01:26 PM |
| fr | kiki_tchyou | cool | Female | bottle washer | Apr 21, 2010 04:09 PM | |
| kiki_tchyou | unemployed | Apr 22, 2010 03:00 PM | ||||
| dinkyland | per | jajah | cool | Male | bottle washer | May 10, 2010 09:43 PM |
| per | 123 | Male | bottle washer | May 27, 2010 10:43 PM | ||
| UK | one | aleggett | cool | Male | bottle washer | Jun 8, 2010 08:22 AM |
| gotting | cool | bottle washer | Jun 16, 2010 09:14 PM | |||
| orlando | line | grstearns | Male | engineer | Aug 18, 2010 03:20 PM | |
| koko | per | donar | cool | Male | bottle washer | Aug 25, 2010 03:19 PM |
| 456567 | per | etwertewrt | Male | unemployed | Aug 26, 2010 12:15 PM | |
| line | Anonymous | cool | bottle washer | Sep 5, 2010 03:27 PM | ||
| aaaaaaaaaaaaaaaaaaaaaaa | one | Anonymous | cool | Female | bottle washer | Sep 5, 2010 03:27 PM |
| Prague | one | jan7 | cool | Male | engineer | Sep 5, 2010 04:00 PM |
| nances | cool | bottle washer | Sep 22, 2010 03:03 PM | |||
| 515 | per | Anonymous | Male | unemployed | Oct 7, 2010 06:09 AM | |
| Right here | line | nances | Male | engineer | Dec 17, 2010 02:51 PM | |
| London | per | bmcdade | cool | Male | engineer | Dec 17, 2010 03:55 PM |
| cghcfghf | per | gsdfgsdfg | cool | Male | engineer | Apr 15, 2011 07:08 AM |
| cfdfd | cool | bottle washer | Apr 25, 2011 08:53 PM | |||
| austin | one | texaszags | Female | unemployed | May 3, 2011 07:08 PM | |
| per | xdavex | cool | Male | engineer | Jun 21, 2011 08:54 PM | |
| sdf | per | xdavex | cool | Male | engineer | Jun 21, 2011 08:54 PM |
| line | Frederic | cool | bottle washer | Jul 21, 2011 08:55 PM | ||
| bandung | one | ngadiman.sentosa@gmail.com | cool | bottle washer | Jul 27, 2011 01:03 PM | |
| bandung | one | ngadiman.sentosa@gmail.com | cool | bottle washer | Jul 27, 2011 01:03 PM | |
| hello | per | ngadiman.sentosa@gmail.com | cool | bottle washer | Jul 27, 2011 01:03 PM |
| File | Version | Size | Modified | |
|---|---|---|---|---|
| ||||
Copyright © 2011 MindTouch, Inc. Powered by
My immediate goal is a simple polling template...
(You just add auto-refresh )
No. Was just a little side-experiment. Did you have anything in particular in mind?
First of I would like you to know I really like this form template. Thanks!
I have been using the form as a "template" to add properties to a page. I use the values inside the last list element to load the form with "current settings"
Unfortunately only text controls allow setting a value. I would like to have that for check boxes, select list and radio buttons as well.
A datepicker would be awesome.
I will take some time to make an example of what I am accomplishing with it.
That's a reasonable request. Let me think about the best way to do it.
There ya go. Enjoy!
Do you have any idea on how UpdateStore could work under https?
I'm sorry but I actually have no idea, and because I don't have any wikis on https I can't even test. UpdateStore is dependent on the DekiApi extension, so I'd post a question to the forums and see if you can get a useful response from someone who has done this (or the MindTouch guys).