Use date picker in a field while creating a tiddler

Here is a NewContact button I use to create a new contact.

\define newContact()
    <$action-sendmessage
        $message="tm-new-tiddler"
        title="New Contact"
        tags="Contact"
        first-met-on=""/>
\end

<$button class=<<tv-config-toolbar-class>> selectedClass="tc-selected" tooltip="New Contact" actions=<<newContact>>>
  {{$:/core/images/quote}}
</$button>

Then I installed the Date Picker Plugin and wanted to use it in the ‘first-met-on’ field. So, I modified the corresponding line to look like this:

first-met-on=<$edit-date field="first-met-on" format="YYYY-MM-DD ddd" />

This, obviously, was a disaster!

How do I get the date picker tool to work in this scenario?

Or I am using a wrong tool/ plugin and need to do this in some other way?

Hi deshmukh
you need to specify field.
I think your text should read:

first- met-on: <$edit-date field=“first-met-on” format=“YYYY-MM-DD ddd” />

Regards
Scot

1 Like

@Scot Thanks. So, I changed the code to look like this:

\define newContact()
    <$action-sendmessage
        $message="tm-new-tiddler"
        title="New Contact"
        tags="Contact"
        first- met-on: <$edit-date field=“first-met-on” format=“YYYY-MM-DD ddd” />
\end

<$button class=<<tv-config-toolbar-class>> selectedClass="tc-selected" tooltip="New Contact" actions=<<newContact>>>
  {{$:/core/images/quote}}
</$button>

And I thought that when I click in the field, I will be presented a nice date picker. But that did not work. It produced several other fields.

Am I missing something? Is there something else I need to change?

<$action-sendmessage $message="tm-new-tiddler" ...> defines the initial values of the desired fields.
But it doesn’t change anything in the default EditTemplate. To actually use the <$edit-date> widget in the EditTemplate, do this:

  1. Create a tiddler (e.g., NewContactEditTemplate), tagged with $:/tags/EditTemplate, containing:
<$list filter="[<currentTiddler>tag[Contact]]">
First met on: <$edit-date field="first-met-on" format="YYYY-MM-DD ddd" />
</$list>
  1. While viewing this new edit template tiddler, click on the $:/tags/EditTemplate tag “pill”, and drag-and-drop the NewContaactEditTemplate title so it is just after $:/core/ui/EditTemplate/body

  2. To hide the default display of the “first-met-on” field (so only your custom field input is shown in the editor), create a tiddler named $:/config/EditTemplateFields/Visibility/first-met-on and set it’s text field value to hide

enjoy,
-e

@EricShulman Thanks. That was perfect.

@EricShulman There is one glitch, though. I can not pick up a date. I can change it. But I can not delete it — like I would delete the value from the field. Even if I remove the entire text from the date picker, the field continues to carry the value.

How can I set things such that I can delete the date from the date picker?

As you noted, it appears that blank input is ignored and the $edit-date widget doesn’t allow you to clear the field contents. However, I didn’t write the Date Picker plugin — based on Pikaday, so there little I can do to change it’s behavior.

Fortunately, there is a way to add some buttons next to the $edit-date widget that can also manipulate the same field.

Try this:

<$list filter="[<currentTiddler>tag[Contact]]">
First met on: <$edit-date field="first-met-on" format="YYYY-MM-DD ddd" />
<$button> {{$:/core/images/close-button}} <$action-setfield first-met-on=""/></$button>
<$button> {{$:/core/images/delete-button}} <$action-deletefield first-met-on/></$button>
</$list>
  • The first button clears the field contents but leaves it defined in the tiddler.
  • The second button completely removes the field definition from the tiddler.
  • You can add either button (or both buttons) to your NewContactEditTemplate, depending upon your needs.

enjoy,
-e

1 Like

@EricShulman Thanks. That did solve the problem. I have come to realize that I will be using the same code multiple times in my view template. And I was wondering if I can define it once and keep reusing it. But I am asking that as a separate question.