Results 1 to 2 of 2

Thread: formatting datefield output on submit

  1. #1

    Default formatting datefield output on submit

    I'm using a Date field in a new-record form for a mySQL DB. See the "expectedDate" form item in the code below.

    Code:
    newRecordForm = new Ext.FormPanel({
        bodyStyle: 'padding:10px',
        items: [
            {name: 'eventTitle', xtype:'textfield', fieldLabel: 'Event title', width: 300, maxLength: 255, allowBlank: false, blankText: 'Event title is required'},
            {name: 'eventType', xtype:'combo', fieldLabel: 'Type', store: TypeStore, mode: 'local', triggerAction: 'all', displayField: 'itemName', valueField: 'itemValue', value: 'Film', editable: false}, 
            {name: 'expectedDate', xtype: 'datefield', fieldLabel: 'Date expected', editable: false},
            {name: 'notes', xtype: 'textfield', fieldLabel: 'Notes', width: 300, maxLength: 255}
        ],
        buttons: [
            {text: 'Save and Close', handler: createNewRecord},
            {text: 'Cancel', handler: function(){newRecordWindow.hide();}}
        ]
    });
    function createNewRecord() {
        if( newRecordForm.form.isValid() ) {
            newRecordForm.form.submit({
                url: 'actions.php', waitMsg: 'Please wait...',
                params: {task: 'ADD'},
                success: addSuccessResponse, failure: failureResponse
            });
        } else {
            Ext.MessageBox.alert( 'Warning', 'Your form is not valid!' );
        }
    }
    newRecordWindow = new Ext.Window({
        id: 'newRecordWindow', title: 'Add an item',
        layout: 'form', width: 650, closable: false,
        items: newRecordForm
    });
    Question: is it possible to convert the datefield value to mySQL format automatically upon form submission, while still having it appear in the date selector as a "human-readable" date?

    I tried adding format: 'Y-m-d' to the datefield definition, but that forces the input field to display the selected date in MySQL format. I can also add editable: false so the user can't over-type that value. This isn't really an ideal solution though, because MySQL-format dates are less readable to my users. Ideally, I'd like the selected date to appear in the field as a human-readable date, but magically convert to a mySQL-style date when the submit button is clicked. And, if it could be done in the form definition, I could reuse my createNewRecord function elsewhere.

    There's no "outputFormat" config item for datefield, but that's what I'm looking for.

  2. #2

    Default

    Never mind, just found a relevant thread & Saki's extension at http://extjs.com/forum/showthread.php?t=25900

Posting Permissions

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