PDA

View Full Version : [resolved] timefield format?



Nikoms
8 Apr 2008, 9:29 AM
Hello all!

I use time and datefield of Ext and I have a little question about the timefield.

To know what I need, lets see how I use the datefield.

I have a date in this format : "Y-m-d" (from mysql) and my date format to display is "j/n/Y"... So when I set the value to the datefield I do this :



myDateField.dateFormat = "Y-m-d";
myDateField.setValue(myValue);

And It shows my date in the format of my config object : "j/n/Y"...

Perfect!

But is it possible to have the same thing for timeField?

For example, I want that the displayed time format is "H:i"... But the data I receive is "H:i: s"

Is it possible to do something like this :


myTimeField.timeFormat = "H:i:s";
myTimeField.setValue(myValue);


So the displayed hour will be "H:i"?

I hope I'm clear enough :)


Thank you!

dlbjr
8 Apr 2008, 10:00 AM
//Use This for object
myTimeField.timeFormat = 'H:i';
myTimeField.setValue(myValue);

//Use this when submitting form
form.getForm().submit( {
params: {
mtime: Format.date(myDateField, 'H:i:s')
},
url : 'WhatEver',
waitMsg : 'Saving data...'
});

Nikoms
8 Apr 2008, 11:50 AM
It does'nt work :(

I forgot to specified that the format was in the config...



timeField = new Ext.form.TimeField({format:"H:i",name:name,renderTo:oTable.child('td.datetime_timeField'),invalidClass:"error"});
....
....
var myValue = "18:10:00";
timeField.timeFormat = "H:i:s";
timeField.setValue(myValue);


This doesn't work and let the field empty...

dlbjr
8 Apr 2008, 1:00 PM
//Your code
var myValue = "18:10:00";
timeField.timeFormat = "H:i:s";
timeField.setValue(myValue);




//Try This
var myValue = '18:10:00';
//Sets how the time will be viewed in the drop down.
timeField.timeFormat = 'H:i';
//Set the default value
timeField.setValue(Date.parseDate(myValue, 'H:i:s'));

Nikoms
8 Apr 2008, 1:20 PM
Thank you very much it works!
this line isn't necessary because I already specified the format in the config object :

timeField.timeFormat = 'H:i';

So this is it, ... simple :)


var myValue = '18:10:00';
timeField.setValue(Date.parseDate(myValue, 'H:i:s'));


Thank you again