<p>Long story short, this is a bug in Craft 2.x that's already been fixed in the Craft 3.x branch.</p>

<p>Considering there is a <a href="https://craftcms.stackexchange.com/questions/8348/how-do-i-save-a-plugins-date-settings-field/8358">workaround</a> for 2.x and the proper fix would be pretty ugly in 2, we're just going to let this one die a slow death with the release of Craft 3.</p>

CC BY-SA 3.0
2015-04-07T20:00:26.327Z
2015-04-07T20:00:26.327Z
2017-04-13T12:51:00.200Z
Brad Bell
<p>In my plugin settings page, I have a startDate input which is a dateTime field.</p>

<p><strong>_settings.html</strong></p>

<pre><code>{{
    forms.dateField({
     'label': 'Start Date'|t,
     'instructions': 'Choose a date'|t,
     'id': 'myStartDate',
     'name': 'myStartDate',
     'placeholder': 'mm/dd/yyyy',
     'value': settings.myStartDate,
     'errors': settings.getErrors('myStartDate')
    })
}}
</code></pre>

<p>My data is getting saved correctly - I can see it:</p>

<p><strong>json</strong></p>

<pre><code>  ....
"myStartDate": {
    "date": "2015-04-13 05:00:00
}
  ....
</code></pre>

<p>So I thought cool. I just need: <code>myStartDate.date</code> and all is well. No luck.</p>

<p>What is curious to me, is when I fill out my start date, but my form fails validation, the date that I have entered is correctly repopulated. I don't have to re-enter the date.</p>

<p>But, once I successfully submit my settings, and then come back, my date field is no longer populated.</p>

<p>I've tried <code>myStartDate</code> and <code>myStartDate.date</code> and <code>myStartDate|date("m/d/Y")</code> but all with no luck.</p>

<p>I feel like I'm abusing this community with so many questions lately. I know the dateTime field needs to be a dateTime object - and I assume that's why it's not working for me. I'm not passing it what it needs.</p>

<p>Thank you for your time!</p>

CC BY-SA 3.0
2015-04-07T07:52:51.543Z
No worries about "abusing" – this site is in beta and needs all the questions it can get, and this is a legitimate one. There seems to be some issues with how the plugin's settings model retrieves DateTime objects from the database – [see this thread](http://craftcms.stackexchange.com/a/8358/1098) for a workaround.
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2015-04-07T12:10:20.160Z
Well, I feel slightly better now, I did read through the post you linked to prior to posting my question and I thought to myself - surely this isn't what I need - it's got to be something I'm doing. At least I'm going down the right path(s) I suppose. 

Do you think it's "bug worthy" to bring up to the folks at Pixel and Tonic?

Thank you again!
Damon
CC BY-SA 3.0
2015-04-07T12:20:27.470Z
I already sent Brad Bell a DM on Twitter asking him to check out the original thread, so hopefully he'll be able to shed some light on the matter :)
Mats Mikkel Rummelhoff
<plugin-development><datetime><validation>
Repopulate dateTime field in plugin settings page
# Repopulate dateTime field in plugin settings page

(Asked by: username_0 on 2015-04-06)

In my plugin settings page, I have a startDate input which is a dateTime field.
_settings.html
{{
    forms.dateField({
     'label': 'Start Date'|t,
     'instructions': 'Choose a date'|t,
     'id': 'myStartDate',
     'name': 'myStartDate',
     'placeholder': 'mm/dd/yyyy',
     'value': settings.myStartDate,
     'errors': settings.getErrors('myStartDate')
    })
}}

My data is getting saved correctly - I can see it:
json
  ....
"myStartDate": {
    "date": "2015-04-13 05:00:00
}
  ....

So I thought cool. I just need: myStartDate.date and all is well. No luck.
What is curious to me, is when I fill out my start date, but my form fails validation, the date that I have entered is correctly repopulated. I don't have to re-enter the date.
But, once I successfully submit my settings, and then come back, my date field is no longer populated.
I've tried myStartDate and myStartDate.date and myStartDate|date("m/d/Y") but all with no luck.
I feel like I'm abusing this community with so many questions lately. I know the dateTime field needs to be a dateTime object - and I assume that's why it's not working for me. I'm not passing it what it needs.
Thank you for your time!

**Tags:** plugin-development, datetime, validation

> **Comments:**
> **username_1**: No worries about "abusing" – this site is in beta and needs all the questions it can get, and this is a legitimate one. There seems to be some issues with how the plugin's settings model retrieves DateTime objects from the database – [see this thread](http://craftcms.stackexchange.com/a/8358/1098) for a workaround.  
> **username_0**: Well, I feel slightly better now, I did read through the post you linked to prior to posting my question and I thought to myself - surely this isn't what I need - it's got to be something I'm doing. At least I'm going down the right path(s) I suppose.   Do you think it's "bug worthy" to bring up to the folks at Pixel and Tonic?  Thank you again!  
> **username_1**: I already sent username_2 a DM on Twitter asking him to check out the original thread, so hopefully he'll be able to shed some light on the matter :)  

---

## 1 answers

### Answer by username_2 on 2015-04-07. Score: 2 | Accepted answer

Long story short, this is a bug in Craft 2.x that's already been fixed in the Craft 3.x branch.

Considering there is a [workaround](https://craftcms.stackexchange.com/questions/8348/how-do-i-save-a-plugins-date-settings-field/8358) for 2.x and the proper fix would be pretty ugly in 2, we're just going to let this one die a slow death with the release of Craft 3.


---

