Table of contents
    No headers

    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:

    1. TEST_Showform(), an enhanced version of SteveB's Showform() template.  This allows all sorts of different form elements to be presented.
    2. UpdateStore().  This subscribes to the "publish" button on the form, and appends it to the page property "formdata".  The property is an array.
    3. TsTable(), which is handed the data from the page property and displays it in a sortable table.

    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.";
    

     

    Name:
    Occupation
    Sex Male Female
    this is cool
    Another radio style one
    per
    line
    Location:
    THIS BREAKSERROR: unknown input type 'hello'
    locationRadio2namecoolsexoccupationtime
      neilw  unemployedAug 19, 2009 07:21 PM
      neilw  unemployedAug 19, 2009 07:24 PM
    NJlineneilwcoolMalebottle washerAug 19, 2009 07:31 PM
    sssperlabben2004coolMaleunemployedAug 21, 2009 12:06 PM
    DavesperDavecoolMaleengineerAug 24, 2009 07:44 PM
    AmlinegouwzeecoolMaleengineerAug 24, 2009 08:50 PM
    ssonemwooscccoolMaleunemployedAug 24, 2009 09:19 PM
    TexasperjraichcoolMaleengineerAug 24, 2009 09:29 PM
    UKonecgarcia MaleengineerAug 25, 2009 07:46 AM
    New Zealand zippgunncoolMaleengineerAug 27, 2009 09:33 AM
    KielperbaumcoolMaleengineerSep 1, 2009 09:54 AM
    hereonemecoolMalebottle washerSep 1, 2009 03:43 PM
    herepersean MaleengineerSep 17, 2009 01:20 PM
     oneseancoolMalebottle washerSep 23, 2009 02:16 PM
    tampopolineimattdotnetcoolMalebottle washerSep 25, 2009 08:11 PM
    tampopolineimattdotnetcoolMalebottle washerSep 25, 2009 08:11 PM
    BluefieldperGlencoolMalebottle washerOct 3, 2009 04:24 PM
    fgfgslinejonvercoolFemaleengineerOct 26, 2009 06:52 PM
    torinopergiuliocoolMaleunemployedOct 27, 2009 06:02 PM
    zuruzpercptregeditcoolMaleengineerDec 18, 2009 03:21 PM
    CAperCuzz'coolMalebottle washerJan 14, 2010 11:48 PM
     perAnonymouscoolMaleunemployedJan 30, 2010 11:38 PM
    thereperkevans@7ticks.comcoolMaleengineerFeb 18, 2010 01:24 AM
    HereperTestingcoolMalebottle washerFeb 18, 2010 09:30 AM
    HereperTestingcoolMalebottle washerFeb 18, 2010 09:30 AM
    LondononewaveydaveycoolMaleengineerFeb 26, 2010 02:44 PM
    asasasoneTestcoolMaleunemployedMar 5, 2010 08:46 AM
    HamburgoneTestcoolMaleunemployedMar 5, 2010 08:47 AM
    rpertercoolMalebottle washerMar 8, 2010 01:26 PM
    hamburglineSeGocoolMaleunemployedMar 8, 2010 01:26 PM
    fr kiki_tchyoucoolFemalebottle washerApr 21, 2010 04:09 PM
      kiki_tchyou  unemployedApr 22, 2010 03:00 PM
    dinkylandperjajahcoolMalebottle washerMay 10, 2010 09:43 PM
     per123 Malebottle washerMay 27, 2010 10:43 PM
    UKonealeggettcoolMalebottle washerJun 8, 2010 08:22 AM
      gottingcool bottle washerJun 16, 2010 09:14 PM
    orlandolinegrstearns MaleengineerAug 18, 2010 03:20 PM
    kokoperdonarcoolMalebottle washerAug 25, 2010 03:19 PM
    456567peretwertewrt MaleunemployedAug 26, 2010 12:15 PM
     lineAnonymouscool bottle washerSep 5, 2010 03:27 PM
    aaaaaaaaaaaaaaaaaaaaaaaoneAnonymouscoolFemalebottle washerSep 5, 2010 03:27 PM
    Pragueonejan7coolMaleengineerSep 5, 2010 04:00 PM
      nancescool bottle washerSep 22, 2010 03:03 PM
    515perAnonymous MaleunemployedOct 7, 2010 06:09 AM
    Right herelinenances MaleengineerDec 17, 2010 02:51 PM
    LondonperbmcdadecoolMaleengineerDec 17, 2010 03:55 PM
    cghcfghfpergsdfgsdfgcoolMaleengineerApr 15, 2011 07:08 AM
      cfdfdcool bottle washerApr 25, 2011 08:53 PM
    austinonetexaszags FemaleunemployedMay 3, 2011 07:08 PM
     perxdavexcoolMaleengineerJun 21, 2011 08:54 PM
    sdfperxdavexcoolMaleengineerJun 21, 2011 08:54 PM
     lineFredericcool bottle washerJul 21, 2011 08:55 PM
    bandungonengadiman.sentosa@gmail.comcool bottle washerJul 27, 2011 01:03 PM
    bandungonengadiman.sentosa@gmail.comcool bottle washerJul 27, 2011 01:03 PM
    helloperngadiman.sentosa@gmail.comcool bottle washerJul 27, 2011 01:03 PM
    Tag page

    Files 1

    FileVersionSizeModified 
    Viewing 15 of 15 comments: view all
    Now you just want AJAX reloading and notification :)
    Posted 07:16, 7 Aug 2009
    Yes on the reloading. What kind of notification?

    My immediate goal is a simple polling template...
    Posted 07:50, 7 Aug 2009
    @crb Yes on the reloading. What kind of notification?
    Posted 07:50, 7 Aug 2009
    Thats awesome!
    (You just add auto-refresh )
    Posted 11:24, 7 Aug 2009
    By the notification I meant "not an alert()" :)
    Posted 12:01, 7 Aug 2009
    something else i always having trouble with is the date format... is there a way to change it because sorting it the way it is presented is not working as it is most likely supposed to be (alphanumeric sorting of the weekday instead of sorting by date).
    Posted 01:59, 1 Sep 2009
    @baum I have added a bit of code to convert the date format into something that TSTable() understands. The ultimate fix to this is to improve the date-recognition code in TsTable(); it's a bit wonky right now.
    Posted 02:59, 1 Sep 2009
    Are you still working on this, Neil?
    Posted 14:52, 13 Jun 2010
    @gouwzee
    No. Was just a little side-experiment. Did you have anything in particular in mind?
    Posted 03:25, 14 Jun 2010
    Yes,
    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.
    Posted 05:08, 14 Jun 2010
    @gouwzee
    That's a reasonable request. Let me think about the best way to do it.
    Posted 05:31, 14 Jun 2010
    Great! Much appreciated.
    Posted 14:20, 14 Jun 2010
    @gouwzee
    There ya go. Enjoy!
    Posted 06:19, 15 Jun 2010
    Neil, I tried the form on a deki website I recently turned into https. The form throws an error AFTER the first entry. I guess it is able to create the property and write it once. After that, I get the "an error occured updating .."
    Do you have any idea on how UpdateStore could work under https?
    Posted 00:13, 5 Aug 2010
    @gouwzee
    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).
    Posted 05:44, 5 Aug 2010
    Viewing 15 of 15 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by