0

I've been trying to find an approach on how to fix the issue I have, but I could not find it in Google nor S.O, that's why I'm posting this question.

I have two components of type: timefield that are represented in this piece of code:

{
            xtype: 'timefield',
            format: 'H:i',
            increment: 30,
            name: 'shiftStartTime',
            itemId: 'shiftStartTime',
            fieldLabel: 'Shift Start Time',
            required: true,
            value: '00:00'                
        }, {
            xtype: 'timefield',
            format: 'H:i',
            increment: 30,
            name: 'shiftEndTime',
            itemId: 'shiftEndTime',
            fieldLabel: 'Shift End Time',
            required: true,
            value: '00:00'
        },

What I'm doing is easy, actually, I'm trying to set a value for the fields based on an entity that comes from server. I already managed to retrieve the entity which has two fields: 'hour' and 'minute', I want to set the concatenated value to both components, but for some reason, it always display blank. Here's the piece of code I implemented in order to set the value:

setPreEnteredTimes: function(userProfileItem) {
    var me = this,
        shiftStartTimeComp = me.getItem('shiftStartTime'),
        shiftEndTimeComp = me.getItem('shiftEndTime'),
        hh = userProfileItem.get('hour'),
        mm = userProfileItem.get('minute');


    var displayStr = hh + ':' + mm;

    shiftStartTimeComp.setValue(displayStr);

    shiftEndTimeComp.setValue(displayStr);


},

I've already tried even creating a new Date and using Ext.Date.format() using H:i but not working, the timefield is always displaying blank.

Version of ExtJS is 4.2.3

Thanks in advance.

Marcelo Tataje
  • 3,849
  • 1
  • 26
  • 51

1 Answers1

0

There is nothing wrong with timefields and .setValue(). I'm sure that you will get an error like me.getItem(...) is not a function on the console. Here is a fiddle with an example: https://fiddle.sencha.com/#fiddle/17al

Replace me.getItem() with a component query like this (included in fiddle):

var shiftStartTimeComp = Ext.ComponentQuery.query('timefield[name="shiftStartTime"]', me)[0];

Tyr
  • 2,810
  • 1
  • 12
  • 21
  • I'm not receiving any javascript message (neither alert nor console output) referring to undefined to "getItem()" method since I'm working over a kind of framework I implemented for my view components. While debugging, "getItem()" is always returning the timefield component without issues. I've already tried the ComponentQuery approach but it does not work. Thanks. – Marcelo Tataje Mar 17 '16 at 17:16