We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38290
    • 712 Posts
    I'm working on a custom component (based off Doodles) that uses xtype:'datefield' in the Create and Update modal window. I can't get the ExtJS to both send and receive the date in integer format (U) as well as display it using Y-m-d.

    If I set the format to U, it works as desired however displays the value of the datepicker as an arbitrary number. I'd like to to display in human readable form.

    This is the ExtJS I'm using in my .grid.js file:

    		{
    			xtype: 'datefield',
    			fieldLabel: _('horders.createdon'),
    			name: 'createdon',
    			anchor: '100%',
    			format: 'Y-m-d', // make it display correct but sends it to server as Y-m-d
    			//format: 'U', // sends to server correct but displays as int
    			submitFormat: 'U', // doesn't seem to do anything
    			dateFormat:'U'
    			}

    This question has been answered by dinocorn. See the first response.

      jpdevries
      • 38290
      • 712 Posts
      I'm a minimalist, so of course I'm curious if it's possible to do without this custom ExtJS extension but it looks like I may be on to something using the extension this person made, which supports configurable submitFormat for an 'xdatefield' type
      http://www.sencha.com/forum/showthread.php?25900-XDateField-with-configurable-submitFormat
        jpdevries
        • 38290
        • 712 Posts
        This will send and save it to the database OK from the create Window:
        {
        			xtype: 'xdatefield',
        			fieldLabel: _('horders.createdon'),
        			name: 'createdon',
        			anchor: '100%',
        			format: 'Y-m-d', // make it display correct but sends it to server as Y-m-d
        			submitFormat: 'U', // doesn't seem to do anything
        			value: new Date(),
        }
        


        but I'm having trouble with the same datefield, in the Update Window. With is code, it works ok but I can't get it to display in Y-m-d format, it displays as an integer (the raw value from the db). I believe this is because I'm having to set format to 'U' to get it to expect values in that format. I just want to tell it, expect values in U for, always display them in Y-m-d form
        		{
        			xtype: 'xdatefield',
        			fieldLabel: _('horders.createdon'),
        			name: 'createdon',
        			anchor: '100%',
        			format: 'U', // make it display correct but sends it to server as Y-m-d
        			dateFormat:'Y-m-d',
        			submitFormat: 'U', 
        			renderer: Ext.util.Format.dateRenderer('Y-m-d')
        		}
        
          jpdevries
        • discuss.answer
          • 38290
          • 712 Posts
          Ok so looks like the reason my updater wasn't working is it didn't have U in the altFormats. Geesh.

          Final code for updater window:
          		{
          			xtype: 'xdatefield',
          			fieldLabel: _('horders.createdon'),
          			name: 'createdon',
          			anchor: '100%',
          			format: 'Y-m-d', // make it display correct but sends it to server as Y-m-d
          			dateFormat:'Y-m-d',
          			submitFormat: 'U', 
          			renderer: Ext.util.Format.dateRenderer('Y-m-d'),
          			altFormats:'U|u|m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d|n-j|n/j'
          		}]
          


          Final code for creator window:
          {
          			xtype: 'xdatefield',
          			fieldLabel: _('horders.createdon'),
          			name: 'createdon',
          			anchor: '100%',
          			format: 'Y-m-d', // make it display correct but sends it to server as Y-m-d
          			submitFormat: 'U', // doesn't seem to do anything
          			value: new Date(),
          }
          
            jpdevries