1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Datepicker not updating value when existing value is set

Discussion in 'XenForo Development Discussions' started by Deek, Sep 26, 2014.

  1. Deek

    Deek Member

    I'm creating a little admin section that is a text box and a date picker. Here is the field for the date picker:

        <dl class="ctrlUnit">
            <dt><label for="ctrl_effectiveDate">Effective Date:</label><dt>
                <input type="date" name="effectiveDate" value="{$item.effectiveDate}" class="textCtrl" id="ctrl_effectiveDate" />
    When I include {$item.effectiveDate} the date picker defaults to today and no matter what I change it to it will not update when I save because the value attribute will retain the timestamp (value="1411686000"). I noticed in other places in XenForo where the date picker is used the value will become blank but for some reason mine doesn't follow that behavior.

    If I do not include {$item.effectiveDate} in the value I can update the item but there is no way to show what it is currently set at. The other two fields title and text always seem to update. Any idea what I'm missing?

    CREATE TABLE `item` (
      `item_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `title` varchar(75) NOT NULL DEFAULT '',
      `text` text NOT NULL,
      `effectiveDate` int(10) unsigned NOT NULL,
      PRIMARY KEY (`item_id`)
    Last edited: Sep 26, 2014
  2. Jeff Berry

    Jeff Berry Well-Known Member

    I don't think a timestamp is the proper format for the value.

    If you look at other uses of the date picker in XF, you'll notice they convert to a "picker" format first (which is Y-m-d) if I remember correctly.

    Try changing your value to this:
    {xen:date {xen:if $item.effectiveDate, $item.effectiveDate, $serverTime}, picker}
    Chris D likes this.
  3. Deek

    Deek Member

    I ended up translating the timestamp by creating a DateTime object in the controller.
    $dateTime = new DateTime('@' $item['effectiveDate']);
    $item['effectiveDate'] = $dateTime->format('Y-m-d');
    Just a note for anyone playing around with dates. Don't forget your timezone matters!
  4. Nobita.Kun

    Nobita.Kun Well-Known Member

    Or use this example:
    Jeff Berry likes this.
  5. Jeff Berry

    Jeff Berry Well-Known Member

    Using the built in XenForo functions adjusts to the timezones by default. However your solution, though not ideal, is fine.
  6. Deek

    Deek Member

    I ended up using this as it is vastly better than my original way.
    Jeff Berry likes this.

Share This Page