Dynamic Entries

30 views
Skip to first unread message

Chris Eichenberg

unread,
Nov 8, 2023, 3:32:47 PM11/8/23
to TiddlyWikiClassic
aaah, it's me again. Thinking of a template to record Census entries. Of course some families might two entries some might have more than two. So I would like to find an alternate way (if such a thing is possible) that would be more efficient. Is there way to add new lines as required ( not tiddlers just lines ) within a given tiddler? 

there is other side of the coin, but going with "one crisis at a time" viewpoint.

Jon

unread,
Nov 8, 2023, 6:49:32 PM11/8/23
to TiddlyWikiClassic
Hi, Chris,

Not sure if I fully understand what you're shooting for. Are you looking for a textbox to show a certain number of lines, or for there to be a certain number of fields (input boxes) to record the entries? How is the number needed determined? That is, would the person first type the number of people into a field and then you'd want the right number of boxes/lines to appear?

Something along this line could certainly be done with a macro: for example, put a "plus" button in your template that runs a macro which adds a new input box to the form (maybe with a simple name like input1, input2, input3... to make it not too hard to collect the data later). I'm trying to think of how you could do it without programming; if you know you'll never need more than some number of fields, you could put them all on the form and use the venerable HideWhenPlugin to respond to an input number of people and un-hide the desired number of fields.

To do it with lines in a textbox, it seems like you'd have to have a text field that isn't on the form at first and appears after entering a number of people and clicking a button. But I'm not sure why you'd want to do it this way, because people can put whatever they want in a textbox and aren't limited to the visible lines.

Any of that helpful?
--Jon

Yakov

unread,
Nov 9, 2023, 12:36:08 AM11/9/23
to TiddlyWikiClassic
Hi Chris,

some more context is really needed to help. In what you're describing, "entry" = tiddler, "template" = a tiddler with template? Or is it like the template is the text which is the same for each "entry" tiddler and you use fields for the data?

For instance, for the latter case, say if you are using fields "name" and "age", you can probably substitute them with "name1" and "age1" and use "name2" and "age2" if you want to store the data for multiple "entries" in a single tiddler. How to modify the template also depends on what you are using already.

Me personally, I'd probably store data in a hidden section in JSON format, like this:

/%
!data
[
  {
    "name": "Molly",
    "age": "40"
  },
  {
    "name": "Ron",
    "age": "15"
  }
]
!%/

as it's easy to extract and modify both with JS and manually (well, for fields there's at least FieldsEditorPlugin, so they are also ok).

Best regards,
Yakov.
четверг, 9 ноября 2023 г. в 02:49:32 UTC+3, Jon:

Chris Eichenberg

unread,
Nov 9, 2023, 1:34:06 PM11/9/23
to TiddlyWikiClassic
basically, the form. . . 
father
mother
child1
+add child

instead of . . . 
father
mother
child1, , , child20  ( large farmer families, always best to hedge bets )

then a way to modify ForEachTiddler output to reflect this. both would be great, this at least this part would save some post editing to order to send to relatives. 

the first question is this possible in some way? or is there at least a K.I.S.S. ( keep it simple, stupid ) workaround to achieve the same ends?

hope this helps.

Yakov

unread,
Nov 12, 2023, 3:01:27 AM11/12/23
to TiddlyWikiClassic
This is surely possible, but the implementation details highly depend on what you're using already. For instance, when using FormTiddlerPlugin, you can do in your template something like:

<button onclick="
    const container = document.getElementById('<id of your form container>')
    const numberOfShownChildren = document.getElementsByClassName('<class of an input used for a child>').length
    container.innerHTML += `<a piece of form that is used per child: inputs etc; if you want to use numbered fields for storage, use ${numberOfShownChildren + 1} to get a number inside this template piece, like name2 ← name${numberOfShownChildren + 1}>`
"> +add child </button>

Substitute the <id of your form container>, <class of an input used for a child>, and <a piece of form ...> bits with what you need – start from something simple, like:

<div id='myForm'>
  <div class='child-subform'>child name 1</div>
</div>
<button onclick="
    const container = document.getElementById('myForm')
    const numberOfShownChildren = document.getElementsByClassName('child-subform').length
    container.innerHTML += `<div class='child-subform'>child name ${numberOfShownChildren + 1}</div>`
"> +add child </button>
четверг, 9 ноября 2023 г. в 21:34:06 UTC+3, komet...@gmail.com:
Reply all
Reply to author
Forward
0 new messages