Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

How do I get values from inputs in a Table View's row?

I have a 'create user' page below based on Kitchen Sink's "table_view_controls_2.js". I can't seem to be able to get the stored values once the user clicks on a 'Save' button. Try it out.

Also if anyone can tell me why the textArea is not filling the whole row (you have to type in it to see that the height is still short).

Thanks!


var win = Titanium.UI.currentWindow;
var tabGroup = win.tabGroup;
var tab = Titanium.UI.currentTab;

var save = Titanium.UI.createButton({
    title:'Save',
    style:Titanium.UI.iPhone.SystemButtonStyle.DONE
});
win.setRightNavButton(save);
save.addEventListener('click', function()
{
    Ti.API.info("Adding");
    Ti.App.fireEvent('showLoading');
    var noteValue = note.text;
    Ti.API.info("Note: "+noteValue);
    Ti.App.fireEvent('hideLoading');
});

function addRow(labelName)
{
    var row = Ti.UI.createTableViewRow({height:50});
    var label = Titanium.UI.createLabel({
        font:{fontSize:13},
        color: '#666',
        text: labelName,
        left: 5,
        height:'auto',
        width:'auto',
        textAlign:'left'
    });
    row.add(label);
    var tf1 = Titanium.UI.createTextField({
        //color:'#336699',
        height:35,
        top:10,
        right:10,
        width:190,
        textAlign: 'right',
        borderStyle:Titanium.UI.INPUT_BORDERSTYLE_NONE
    });
    if(labelName == 'Phone'){
        tf1.keyboardType = Titanium.UI.KEYBOARD_NUMBER_PAD;
    }
    if(labelName == 'E-Mail'){
        tf1.keyboardType = Titanium.UI.KEYBOARD_EMAIL;
    }
    row.add(tf1);
    row.selectionStyle = Ti.UI.iPhone.TableViewCellSelectionStyle.NONE;
    row.className = 'control';
    return row;
}
function addtextarea()
{
    var row = Ti.UI.createTableViewRow();
    var note = Titanium.UI.createTextArea({
        //color:'#336699',
        value: '',
        font:{fontSize:13},
        top:10,
        height: 120,
        width: 290,
        bottom: 10,
        borderStyle:Titanium.UI.INPUT_BORDERSTYLE_NONE
    });    
    row.add(note);
    row.height = 'auto';
    row.selectionStyle = Ti.UI.iPhone.TableViewCellSelectionStyle.NONE;
    row.className = 'control';
    return row;
}

// create table view data object
var data = [];

data[0] = Ti.UI.createTableViewSection({headerTitle:'Basic'});
data[1] = addRow('First Name');
data[2] = addRow('Last Name');
data[3] = addRow('Phone');
data[4] = addRow('E-Mail');
data[5] = Ti.UI.createTableViewSection({headerTitle:'Note'});
data[6] = addtextarea();

var tableView = Ti.UI.createTableView({
    data:data,     
    style: Titanium.UI.iPhone.TableViewStyle.GROUPED
});

win.add(tableView);
— asked April 7th 2010 by Ryan Gartin
  • data
  • row
  • tableview
  • tableviewrow
  • textarea
  • textfield
1 Comment
  • anyone?

    — commented May 28th 2013 by Zak Weiland

1 Answer

  • In your event listener for your save button you want to do:

    var noteValue = note.value;
    

    not note.text;

    Also, I would declare the 'note' variable outside of the addtextarea() function.

    — answered April 7th 2010 by Brendan Lim
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.