Question: A simple way to create a tiddler with many fields (on demand)

200 views
Skip to first unread message

Mohammad

unread,
Jan 7, 2020, 3:56:01 PM1/7/20
to TiddlyWiki
The below code uses a button to create more input boxes to get field-name/field-value pairs from user.
It then will be used to create a tiddler with many fields as user like!

This works, but it seems a bit complicated! 

What do you propose?


\define myTid()       xx$:/temp/sample
\define myfilter()    [range[1,$(flt)$]]
\define id_fldName()  fldn$(cnt)$
\define id_fldValue() fldv$(cnt)$

\define create-recoreds()
<$wikify name=flt text={{{ [<myTid>get[counter]]~[[1]] }}}>
<$list filter=<<myfilter>> variable=cnt>

<<getInputs>>
</$list>
</$wikify>
\end

\define getInputs()
<$edit-text tiddler=<<myTid>> index=<<id_fldName>>  tag=input  default="" placeholder="field name"/>
<$edit-text tiddler=<<myTid>> index=<<id_fldValue>> tag=input  default="" placeholder="field value"/>
\end


<$button>add
<$action-setfield $tiddler=<<myTid>> counter={{{[<myTid>get[counter]add[1]]~[[2]]}}}/>
</$button>
<$button>reset
<$action-setfield $tiddler=<<myTid>> counter="1"/>
<$action-setfield $tiddler=<<myTid>> text=""/>
</$button>

Number of records: <$count filter="[<myTid>indexes[]]" /><br>
Counter: <$transclude tiddler=<<myTid>> field="counter"/><br>


<<create-recoreds>>



TonyM

unread,
Jan 7, 2020, 8:17:30 PM1/7/20
to TiddlyWiki
Mohammad,

I am working on something similar so will avoid reviewing yours for now. Note your typo "create-recoreds" should be "create-records".

Regards
Tony

Mohammad

unread,
Jan 9, 2020, 3:22:31 AM1/9/20
to TiddlyWiki
I have created the below interface to create a tiddler with many fields!
The field name and value pairs are collected from variable number of input boxes

While this work seamlessly I am looking for a simpler code!


To give a try go to tiddlywiki.com create a new tiddler and paste the below code!


\define createMyTiddler()
<$vars newTitle={{{ [<newtiddlerdName>get[text]] }}}>
<$wikify name=flt text={{{ [<datafieldsTid>indexes[]count[]] }}}> 
<$list filter=<<myfilter>> variable="cnt">
<$action-setfield $tiddler=<<newTitle>> 
 $field={{{ [<datafieldsTid>getindex<id_fldName>]  }}} 
 $value={{{ [<datafieldsTid>getindex<id_fldValue>] }}} />
</$list>
</$wikify>
</$vars>

\end


\define datafieldsTid()       $:/temp/sample
\define newtiddlerdName()     $:/temp/tidName
\define myfilter()     [range[1,$(flt)$]]
\define id_fldName()   fldn$(cnt)$
\define id_fldValue()  fldv$(cnt)$

\define create-records()
<$wikify name=flt text={{{ [<datafieldsTid>get[counter]]~[[1]] }}}>
<$list filter=<<myfilter>> variable=cnt>

<<getInputs>>
</$list>
</$wikify>
\end

\define getInputs()
<$edit-text tiddler=<<datafieldsTid>> index=<<id_fldName>>  tag=input  default="" placeholder="field name"/>
<$edit-text tiddler=<<datafieldsTid>> index=<<id_fldValue>> tag=input  default="" placeholder="field value"/>
\end


<!-- Interface -->

<$button>add
<$action-setfield $tiddler=<<datafieldsTid>> counter={{{[<datafieldsTid>get[counter]add[1]]~[[2]]}}}/>
</$button>
<$button>reset
<$action-setfield $tiddler=<<datafieldsTid>> counter="1"/>
<$action-setfield $tiddler=<<datafieldsTid>> text=""/>
<$action-setfield $tiddler=<<newtiddlerdName>> text=""/>
</$button>

Number of records: <$count filter="[<datafieldsTid>indexes[]]" /><br>
Counter: <$transclude tiddler=<<datafieldsTid>> field="counter"/><br>


<<create-records>>

<$edit-text tiddler=<<newtiddlerdName>> field=text tag=input default="" placeholder="new title"/>

<$button actions="">Create Tiddler
<<createMyTiddler>>
</$button>



J Mc

unread,
Jan 9, 2020, 2:33:51 PM1/9/20
to TiddlyWiki
Hi Mohammad

this is another excellent example of how to use TW.
Would it be possible to add tags and a tiddler type selection to the form?


I added an example in the post below, that you may be interested in.

Mohammad

unread,
Jan 9, 2020, 2:45:44 PM1/9/20
to TiddlyWiki

On Thursday, January 9, 2020 at 11:03:51 PM UTC+3:30, J Mc wrote:
Hi Mohammad

this is another excellent example of how to use TW.
Would it be possible to add tags and a tiddler type selection to the form?



The above code is used in Commander!

--Mohammad

 
I added an example in the post below, that you may be interested in.


Many thanks. I will have a look.


--Mohammad

J Mc

unread,
Jan 9, 2020, 3:31:52 PM1/9/20
to tiddl...@googlegroups.com


On Thursday, 9 January 2020 19:45:44 UTC, Mohammad wrote:

On Thursday, January 9, 2020 at 11:03:51 PM UTC+3:30, J Mc wrote:
Hi Mohammad

this is another excellent example of how to use TW.
Would it be possible to add tags and a tiddler type selection to the form?



The above code is used in Commander!

Mohammad

 
 Mohammad

 Many thanks. I will have a look.

 J Mc

TonyM

unread,
Jan 9, 2020, 4:37:08 PM1/9/20
to TiddlyWiki
Mohammad,

I am quite interested in the coding methods you are using. I thought this was an appropriate place to share other methods of adding fields to tiddlers, part of "creating a tiddler".

The "just in time field addition" is where your view template allows you to edit, thus create fields when and if required, rather than creating them before hand. The edit or checkbox etc... does the field creation for you. Of course you need to do this via a template so you can "edit the current Tiddler".

I have a commercial project where I am doing this, the customer asked for additional checkboxes on a person record. Since I expect they will want more in the future I used a Dictionary tiddler to store field names and description, then need only add another to have it appear in their person tiddlers.

<$list filter="[[$:/data/industry-experience-fields]indexes[]]" variable=fieldname>
  <$checkbox field=<
<fieldname>>  checked="yes" unchecked="no" default="no"> <$text text={{{ [[$:/data/industry-expierence-fields]getindex<fieldname>] }}}/></$checkbox><br>
</$list>

So in this case the field will only exist if given a value, so my report logic will test if yes OR "no"/blank.

I am working on a code pattern for generic way to allow edit current tiddler elements. I have more complex solutions but would like to make it easy to use.

Regards
Tony





On Wednesday, January 8, 2020 at 7:56:01 AM UTC+11, Mohammad wrote:

Mohammad

unread,
Jan 9, 2020, 11:59:10 PM1/9/20
to TiddlyWiki


On Friday, January 10, 2020 at 1:07:08 AM UTC+3:30, TonyM wrote:
Mohammad,

I am quite interested in the coding methods you are using. I thought this was an appropriate place to share other methods of adding fields to tiddlers, part of "creating a tiddler".

Thanks Tony! 

The "just in time field addition" is where your view template allows you to edit, thus create fields when and if required, rather than creating them before hand. The edit or checkbox etc... does the field creation for you. Of course you need to do this via a template so you can "edit the current Tiddler".

I have a commercial project where I am doing this, the customer asked for additional checkboxes on a person record. Since I expect they will want more in the future I used a Dictionary tiddler to store field names and description, then need only add another to have it appear in their person tiddlers.

<$list filter="[[$:/data/industry-experience-fields]indexes[]]" variable=fieldname>
  <$checkbox field=<
<fieldname>>  checked="yes" unchecked="no" default="no"> <$text text={{{ [[$:/data/industry-expierence-fields]getindex<fieldname>] }}}/></$checkbox><br>
</$list>

So in this case the field will only exist if given a value, so my report logic will test if yes OR "no"/blank.

This is a nice design pattern! I think this can also provides a textbox for online data gathering like an online questionnaire. Or one can give some numerical values to answers and then calculate the average and like that!
Reply all
Reply to author
Forward
0 new messages