[WARN] Exception in event callback

You must Login before you can answer or comment on any questions.

Hello everyone, I'm new to Titanium and Javascript, so my question could be because i don't know much about how Javascript works. I hope you can give me a hand.

I'm trying to make a ComboBox that one I can click on it a Picker displays. It worked really fine when i did it in the same code where i was adding TextFields, Labels, etc. But that it's not very reusable, so i made a function that creates that ComboBox. But the thing is that I get this error:

[WARN] Exception in event callback. {
    expressionBeginOffset = 2233;
    expressionCaretOffset = 2261;
    expressionEndOffset = 2267;
    line = 94;
    message = "Result of expression 'pickerView.getSelectedRow(0)' [undefined] is not an object.";
    name = TypeError;
    sourceId = 197254720;
    sourceURL = "file://localhost/Users/mahmood1/Library/Application%20Support/iPhone%20Simulator/4.3.2/Applications/1DF9D427-4D75-473E-9929-36997D4BC753/Falabella.app/main/ComboBox.js";
}
And my code is the following:
function createComboBox(data, textField, view){
    var slide_in =  Titanium.UI.createAnimation({bottom:0});
    var slide_out =  Titanium.UI.createAnimation({bottom:-251});
    var pickersWidth = Ti.Platform.displayCaps.platformWidth;
    var tr = Titanium.UI.create2DMatrix();
    tr = tr.rotate(90);
 
    var dropButton = Titanium.UI.createButton({
        style : Titanium.UI.iPhone.SystemButton.DISCLOSURE,
        transform : tr
    });
 
    textField.setBorderStyle(Titanium.UI.INPUT_BORDERSTYLE_ROUNDED);
    textField.setRightButton(dropButton);
    textField.setRightButtonMode(Titanium.UI.INPUT_BUTTONMODE_ALWAYS);
    view.add(textField);    
    var picker_data = [];
     for (var i = 0; i < data.length; i++){
            var row = Ti.UI.createPickerRow({
                title: data[i]
            });
            label = Ti.UI.createLabel({
                font:{
                    fontSize: 50,
                    fontWeight:'bold'
                },
                width: '100%',
                text: data[i],
                textAlign:Titanium.UI.TEXT_ALIGNMENT_CENTER
            });
 
            row.add(label);
 
            picker_data.push(row);
 
        }
 
    var pickerView = Titanium.UI.createView({
    height:251,
    bottom:-251,
    width: pickersWidth
    });
 
 
    var cancel =  Titanium.UI.createButton({
        title:'Cancelar',
        style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
    });
 
    var done =  Titanium.UI.createButton({
        title:'Listo',
        style:Titanium.UI.iPhone.SystemButtonStyle.DONE
    });
 
    var spacer =  Titanium.UI.createButton({
        systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
    });
 
 
    var toolbar=  Titanium.UI.createToolbar({
        top:0,
        items:[cancel,spacer,done]
    });
 
    var picker = Titanium.UI.createPicker({
            top:43
    });
 
    picker.selectionIndicator=true;
 
    picker.add(picker_data);
 
    pickerView.add(toolbar);
    pickerView.add(picker);
 
    textField.addEventListener('focus', function() {
        pickerView.animate(slide_out);
    });
 
    dropButton.addEventListener('click',function() {
        pickerView.animate(slide_in);
        textField.blur();
    });
 
    cancel.addEventListener('click',function() {
        pickerView.animate(slide_out);
    });
 
    done.addEventListener('click',function() {
        textField.value =  pickerView.getSelectedRow(0).title;
        pickerView.animate(slide_out);
    });
 
    pickerView.setZIndex(0);
    view.add(pickerView);
    return textField;
}
What i want to do in that line of code, is set the selected value to the combobox.

Thanks everyone, and please forgive my bad english

1 Answer

Well... never mind, i didn't realize that it had to be 'picker' no 'pickerView'. Anyways, you have that function that could be useful to someone. Regards!

function createComboBox(data, textField, view){
    var slide_in =  Titanium.UI.createAnimation({bottom:0});
    var slide_out =  Titanium.UI.createAnimation({bottom:-251});
    var pickersWidth = Ti.Platform.displayCaps.platformWidth;
    var tr = Titanium.UI.create2DMatrix();
    tr = tr.rotate(90);
 
    var dropButton = Titanium.UI.createButton({
        style : Titanium.UI.iPhone.SystemButton.DISCLOSURE,
        transform : tr
    });
 
    textField.setBorderStyle(Titanium.UI.INPUT_BORDERSTYLE_ROUNDED);
    textField.setRightButton(dropButton);
    textField.setRightButtonMode(Titanium.UI.INPUT_BUTTONMODE_ALWAYS);
    view.add(textField);    
    var picker_data = [];
     for (var i = 0; i < data.length; i++){
            var row = Ti.UI.createPickerRow({
                title: data[i]
            });
            label = Ti.UI.createLabel({
                font:{
                    fontSize: 50,
                    fontWeight:'bold'
                },
                width: '100%',
                text: data[i],
                textAlign:Titanium.UI.TEXT_ALIGNMENT_CENTER
            });
 
            row.add(label);
 
            picker_data.push(row);
 
        }
 
    var pickerView = Titanium.UI.createView({
    height:251,
    bottom:-251,
    width: pickersWidth
    });
 
 
    var cancel =  Titanium.UI.createButton({
        title:'Cancelar',
        style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
    });
 
    var done =  Titanium.UI.createButton({
        title:'Listo',
        style:Titanium.UI.iPhone.SystemButtonStyle.DONE
    });
 
    var spacer =  Titanium.UI.createButton({
        systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
    });
 
 
    var toolbar=  Titanium.UI.createToolbar({
        top:0,
        items:[cancel,spacer,done]
    });
 
    var picker = Titanium.UI.createPicker({
            top:43
    });
 
    picker.selectionIndicator=true;
 
    picker.add(picker_data);
 
    pickerView.add(toolbar);
    pickerView.add(picker);
 
    textField.addEventListener('focus', function() {
        pickerView.animate(slide_out);
    });
 
    dropButton.addEventListener('click',function() {
        pickerView.animate(slide_in);
        textField.blur();
    });
 
    cancel.addEventListener('click',function() {
        pickerView.animate(slide_out);
    });
 
    done.addEventListener('click',function() {
        textField.value =  picker.getSelectedRow(0).title;
        pickerView.animate(slide_out);
    });
 
    pickerView.setZIndex(0);
    view.add(pickerView);
    return textField;
}

Your Answer

Think you can help? Login to answer this question!