We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17422
    • 225 Posts
    Hi,

    it’s possible use a TV date without time on modx revo 2.0.5

    i try this :
    $this->xpdo->lexicon->load('tv_widget');
    
    $v = $value;
    if ($v != '' && $v != '0' && $v != '0000-00-00') {
        $v = strftime('%Y-%m-%d',strtotime($v));
    }
    $this->set('value',$v);
    
    return $this->xpdo->smarty->fetch('element/tv/renders/input/dateSSHeure.tpl');



    and with
    MODx.load({
    {/literal}
        xtype: 'xdatetime'
        ,applyTo: 'tv{$tv->id}'
        ,width: '97%'
        ,name: 'tv{$tv->id}'
        ,dateFormat: MODx.config.manager_date_format
        ,dateWidth: 120
        ,allowBlank: true
        ,value: '{$tv->value}'
    {literal}
        ,listeners: { 'change': { fn:MODx.fireResourceFormChange, scope:this}}
    });
    


    but not work.

    if i change xtype with : xtype: ’xdate’

    idem, not work

    Thanks for your Help.

    Laurent
      • 28215
      • 4,149 Posts
      Use ’datefield’, not ’xdate’.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 17422
        • 225 Posts
        thanks a lot Shaun.

        I wish you a good day.

        Laurent
          • 17422
          • 225 Posts
          i try with date but no work

          i search on google and found :

          datefield

          but no work well,
          the calendar appears in the top left of the window, not next to the fields and the value does not appear in the input

          have you an example ?

          below my code :
          <input id="tv{$tv->id}" type="hidden" class="datefield"
          	value="{$tv->value}" name="tv{$tv->id}"
          	onblur="MODx.fireResourceFormChange();"/>
          
          <script type="text/javascript">
          // <![CDATA[
          {literal}
          MODx.load({
          {/literal}
              xtype: 'datefield'
              ,applyTo: 'tv{$tv->id}'
              ,width: '97%'
              ,name: 'tv{$tv->id}'
              ,dateFormat: MODx.config.manager_date_format
              ,dateWidth: 120
              ,allowBlank: true
              ,value: '{$tv->value}'
          {literal}
              ,listeners: { 'change': { fn:MODx.fireResourceFormChange, scope:this}}
          });
          {/literal}
          // ]]>
          </script>


          <?php
          /**
           * @package modx
           * @subpackage processors.element.tv.renders.mgr.input
           */
          $this->xpdo->lexicon->load('tv_widget');
          
          $v = $value;
          if ($v != '' && $v != '0' && $v != '0000-00-00') {
              $v = strftime('%Y-%m-%d',strtotime($v));
          }
          $this->set('value',$v);
          
          return $this->xpdo->smarty->fetch('element/tv/renders/input/dateSSHeure.tpl');
          



          i attach a printscreen.






          Laurent
            • 3749
            • 24,544 Posts
            Laurent, Maybe I’m misunderstanding your code, but it looks like you might be confused getting and setting TV values. My apologies if this is off the mark. When you have a TV object in code, simply getting and setting its value deals only with the *default* value of the TV.

            To get or set the value of the TV for a specific document, you need to specify the resource ID of the resource you want to set it for. So, to get or set the value for the current resource :

            $id = $modx->resource->get('id');
            
            $val = $tv->getValue($id) // get raw content (a Unix timestamp in this case)
            $val = $tv->renderOutput($id) // get processed content (a datestring in this case)
            
            $tv->setValue($id,'someNewValue');
            


            I can’t remember if the value in the last line would be a timestamp or a date string (or if it will accept either).

            I think one option for you would be to get the date string with renderOutput(), and just strip off the time with:

            $date = substr($date,0,10);

              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting