How to make a default field for a new record?

223 views
Skip to first unread message

Mike Andyl

unread,
Jul 15, 2021, 12:00:22 PM7/15/21
to TiddlyWiki
I want the "url" field to be always visible from the start for all new records. Can I add something to the system so that it always appears on its own?

$:/config/EditTemplateFields/Visibility/url ??????

I already know about custom buttons "tm-new-tiddler", about templates param=, about $:/tags/EditTemplate
But all this requires additional actions one way or another.
I want everything to be as simple as it is now, only with the url field)
Message has been deleted

Brian Radspinner

unread,
Jul 15, 2021, 12:33:16 PM7/15/21
to TiddlyWiki
Try adding the following code to a new tiddler tagged with "$:/tags/EditTemplate"

<div class="tc-edit-fields">
<table class="tc-edit-fields">
<tbody>
<tr class="tc-edit-field">
<td class="tc-edit-field-name">url</td>
<td class="tc-edit-field-value"><$edit-text field="url" default="" tag="input"/></td>
</tr>
</tbody>
</table>
</div>

This will put a table styled like the other fields list with the URL field showing in the tiddler editor.

Álvaro

unread,
Jul 15, 2021, 3:27:17 PM7/15/21
to TiddlyWiki
I don't know if I understand you.
When you create a new (default) tiddler, it has the default fields. You can see them in the info panel (except the text field).

Then you can:
- Create a new tiddler and then add the url field (tm-add-field)
- Create a new tiddler from template tiddler (with url field)

Mike Andyl

unread,
Jul 15, 2021, 6:05:36 PM7/15/21
to TiddlyWiki
Brian, yes, but it looks bad and that's what I want to avoid.

I can make the tags field visible right away $:/config/EditTemplateFields/Visibility/tags, why can't I do the same with the url field?
четверг, 15 июля 2021 г. в 22:27:17 UTC+3, Álvaro:

Eric Shulman

unread,
Jul 15, 2021, 6:43:07 PM7/15/21
to TiddlyWiki
On Thursday, July 15, 2021 at 3:05:36 PM UTC-7 miket...@gmail.com wrote:
Brian, yes, but it looks bad and that's what I want to avoid.

The first problem is that the URL field will appear twice when the field has a value:
* once because it exists as a field in the current tiddler
* and again because the input is tagged as $:/tags/EditTemplate 

To fix this, you can wrap the URL EditTemplate definition in a $list widget, like this:
<$list filter="[<currentTiddler>!has:field[url]]" variable="no_url">
<div class="tc-edit-fields">
<table class="tc-edit-fields">
<tbody>
<tr class="tc-edit-field">
<td class="tc-edit-field-name">url</td>
<td class="tc-edit-field-value"><$edit-text field="url" default="" tag="input"/></td>
</tr>
</tbody>
</table>
</div>
</$list>

The second problem is that the custom URL EditTemplate definition is placed after the "add new field" controls.

To fix this, you can move the custom URL EditTemplate above the "add new field" controls:
* From the URL EditTemplate tiddler view, click on the "$:/tags/EditTemplate" tag pill
* In the list of EditTemplate definitions, drag-and-drop to move the URL EditTemplate above "$:/core/ui/EditTemplate/fields"
 
I can make the tags field visible right away $:/config/EditTemplateFields/Visibility/tags, why can't I do the same with the url field?

You can.  Add another $list widget wrapper to the URL EditTemplate definition, like this:
<$list filter="[[$:/config/EditTemplateFields/Visibility/URL]!text[hide]]" variable="hide_url">
<$list filter="[<currentTiddler>!has:field[url]]" variable="no_url">
<div class="tc-edit-fields">
<table class="tc-edit-fields">
<tbody>
<tr class="tc-edit-field">
<td class="tc-edit-field-name">url</td>
<td class="tc-edit-field-value"><$edit-text field="url" default="" tag="input"/></td>
</tr>
</tbody>
</table>
</div>
</$list>
</$list>

By default, the URL field will be shown.  If you want to hide the URL field,
just create a tiddler named $:/config/EditTemplateFields/Visibility/URL 
and set it's text field content to "hide"

enjoy,
-e

Álvaro

unread,
Jul 15, 2021, 8:00:33 PM7/15/21
to TiddlyWiki
Because you don't have a url field when you create with buttons with the basic "tm-new-tiddler". The created tiddlers have the tags field, but it doesn't have this url field, then it can't be displayed.

Only the usual fields (tags, title, text, ...) have this setting ( $:/config/EditTemplateFields/Visibility/FIELD_NAME ) by default.

For this you need that your button creates the url field. I talk about two options: template tiddler ord second action for create the url field, but there is a easier way:

<$button>
<$action-sendmessage $message="tm-new-tiddler" url="" />
New Tiddler with url field
</$button>

Eric Shulman

unread,
Jul 15, 2021, 8:20:09 PM7/15/21
to TiddlyWiki
On Thursday, July 15, 2021 at 5:00:33 PM UTC-7 Álvaro wrote:
I talk about two options: template tiddler or second action for create the url field, but there is a easier way:

While your $button definition works, it doesn't meet the goals of the OP.  Specifically: I want the "url" field to be always visible from the start for all new records. Can I add something to the system so that it always appears on its own?  The $button solution doesn't address the other ways you can create a new tiddler, such as using the sidebar "New Tiddler" button, or clicking on a link to a missing tiddler and then editing that tiddler.  Only the EditTemplate solution will provide this behavior for all interactive methods of creating new tiddlers.

-e

Álvaro

unread,
Jul 15, 2021, 9:25:29 PM7/15/21
to TiddlyWiki
Yes, because I focused on explaining the problem. The base of the solution is  <$action-sendmessage $message="tm-new-tiddler" url="" />

The hard version is modifing the action-sendmessage in the tiddler $:/core/ui/Actions/new-tiddler
<$action-sendmessage $message="tm-new-tiddler" tags=<<get-tags>>/>
to
<$action-sendmessage $message="tm-new-tiddler" tags=<<get-tags>> url=""/>

Eric Shulman

unread,
Jul 16, 2021, 12:04:57 AM7/16/21
to TiddlyWiki
On Thursday, July 15, 2021 at 6:25:29 PM UTC-7 Álvaro wrote:
Yes, because I focused on explaining the problem. The base of the solution is  <$action-sendmessage $message="tm-new-tiddler" url="" />
The hard version is modifing the action-sendmessage in the tiddler $:/core/ui/Actions/new-tiddler
<$action-sendmessage $message="tm-new-tiddler" tags=<<get-tags>>/>
to
<$action-sendmessage $message="tm-new-tiddler" tags=<<get-tags>> url=""/>

Once again, I have to point out that this only changes the behavior of the "New Tiddler" button and does not fully address the OP goal ("the url field to be always visible from the start for all new records.")

There are at least 6 other ways to interactively create another tiddler:
* New Journal in the Sidebar
* New Image in the Sidebar
* New Here in the Tiddler Menu
* New Journal Here in the Tiddler Menu
* Follow a link to a missing tiddler, and then edit that tiddler
* Any 3rd-party plugin or hand-written custom wikitext that contains a $button using "tm-new-tiddler", 

The only solution that handles all these cases (and any others that I haven't thought of at the moment) is to modify the EditTemplate as suggested by Brian Radspinner, with the small UI improvements suggested by me to remove the duplicate appearance of the "url" field, position it above the "create new field" interface in the tiddler editor, and enable use of $:/config/EditTemplateFields/Visibility/URL

respectfully,
-e

Álvaro

unread,
Jul 16, 2021, 5:11:23 AM7/16/21
to TiddlyWiki
Yes, you are right. I thought in the my usual way to create new records, I don't usualy use new journal or new image.

Then we can use a hack in $:/core/ui/EditTemplate/fields which displays a fake(/"empty") url field, we don't have a real url field until you type and save its value.

The hack would be:

<div class="tc-edit-fields">
<table class={{{ [all[current]fields[]] :filter[lookup[$:/config/EditTemplateFields/Visibility/]!match[hide]] +[count[]!match[0]] +[then[tc-edit-fields]] ~[[tc-edit-fields tc-edit-fields-small]] }}}>
<tbody>
<$list filter="[all[current]fields[]] +[sort[title]]" variable="currentField" storyview="pop">
to
<$list filter="[all[current]fields[]] [[url]] +[sort[title]]" variable="currentField" storyview="pop">

Mike Andyl

unread,
Jul 16, 2021, 8:31:14 AM7/16/21
to TiddlyWiki
Thanks a lot for the tips, they are all good and each has its own bonuses! Now I need to choose the best one for myself :) Very useful and learned a lot about the work of TW.

пятница, 16 июля 2021 г. в 12:11:23 UTC+3, Álvaro:

Mike Andyl

unread,
Jul 16, 2021, 9:06:17 AM7/16/21
to TiddlyWiki
But the last question

* From the URL EditTemplate tiddler view, click on the "$:/tags/EditTemplate" tag pill
* In the list of EditTemplate definitions, drag-and-drop to move the URL EditTemplate above "$:/core/ui/EditTemplate/fields"

Where is the sort order stored? I thought in field list or list-before/after, but did not find it anywhere.

пятница, 16 июля 2021 г. в 15:31:14 UTC+3, Mike Andyl:

Eric Shulman

unread,
Jul 16, 2021, 12:21:01 PM7/16/21
to TiddlyWiki
On Friday, July 16, 2021 at 6:06:17 AM UTC-7 miket...@gmail.com wrote:
* In the list of EditTemplate definitions, drag-and-drop to move the URL EditTemplate above "$:/core/ui/EditTemplate/fields"
Where is the sort order stored? I thought in field list or list-before/after, but did not find it anywhere.

When you re-order tagged items, the new order is stored in the list field of the tag itself.
In this case, that would be: $:/tags/EditTemplate

-e

Reply all
Reply to author
Forward
0 new messages