Search code examples
titaniumtitanium-mobileappceleratorappcelerator-mobile

Appcelerator: Possible to detect @mention in textArea


So I successfully have a nice textArea setup to get user input that will post into a web form I have created. I want to add @mention functionality to the text area, so that if a user types @somename, as they are typing it will query a JSON web service to pull up some values of possible name matches.

My first starting point is to somehow detect changes in the textArea to see if a user is trying to @mention someone

Any thoughts or ideas on how to approach this?

Thank you!


Solution

  • To detect changes in text area you can use change event. Following code would help to start things :

    var textArea = Ti.UI.createTextArea({
        borderWidth: 2,
        borderColor: '#bbb',
        borderRadius: 5,
        color: '#888',
        font: {fontSize:20, fontWeight:'bold'},
        textAlign: 'left',
        value: 'I am a textarea',
        top: 60,
        width: 300, height : 70
    });
    textArea.addEventListener("change", textAreaValueChanged);
    
    function textAreaValueChanged() {
        var newTextAreaValue = textArea.value;
        // now parse this newTextAreaValue according to your need and hit webservice
    }