Results 1 to 2 of 2

Thread: initialize date to last month

  1. #1
    Sencha User
    Join Date
    Oct 2007
    Posts
    585

    Default initialize date to last month

    I want to pull up a form with a DatePicker field initialized to 30 days before today.

    I tried

    {
    xtype: 'datepickerfield',
    width: '100%',
    label: 'From',
    id: 'fromdate',
    name: 'fromdate',
    value: 'lastMonth'
    },

    // below the config clause
    getLastMonth: function(){
    var lastMonth = new Date(today.getTime() - 1000 * 60 * 60 * 24 * 30);
    alert("last month: " + lastMonth);
    return new Date(today.getTime() - 1000 * 60 * 60 * 24 * 30);
    }

    this did not work. fromdate field is left blank.

    I tried in a new file, app/view/LastMonthDateField.js

    Ext.define('FirstApp.view.LastMonthDateField', {
    extend: 'Ext.field.DatePicker',
    xtype: 'LastMonthDateField',
    alias: 'widget.LastMonthDateField'
    requires: [
    'Ext.field.DatePicker'
    ],

    config: {
    value: getLastMonth()
    },

    getLastMonth: function(){
    return new Date(today.getTime() - 1000 * 60 * 60 * 24 * 30);
    }

    }

    then in my config

    {
    xtype: 'LastMonthDateField',
    width: '100%',
    label: 'From',
    id: 'fromdate',
    name: 'fromdate'
    },

    I get an error, [Ext.createByAlias] Cannot create an instance of unrecognized alias: widget.LastMonthDateField

    please tell me how to do this.

  2. #2
    Sencha User
    Join Date
    Oct 2007
    Posts
    585

    Default

    this worked

    {
    xtype: 'datepickerfield',
    width: '100%',
    label: 'From',
    id: 'fromdate',
    name: 'fromdate',
    value: new Date(new Date().getTime() - (1000 * 60 * 60 * 24 * 30))
    },

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •