pec1985 / TiSMSView

Expandable Text Area Module - iOS - Titanium
Other
60 stars 18 forks source link

Disable send button #8

Closed sindresorhus closed 13 years ago

sindresorhus commented 13 years ago

Can you add the ability to disable/enable the send button?

Just like the SMS app. I don't want the user to be able to click the button if there is no text in the textArea.

pec1985 commented 13 years ago

I will add this to the feature request. One question, how would it be used? could you give me an example of how it should be implemented?

sindresorhus commented 13 years ago

The Ti.UI.Button has an enabled boolean that you can change. I've used this in the past to disable some functionality when it's temporary unavailable to the user. For example in this case, I would set the button to enabled: false, bind to the change event on the textArea and then have it set to enabled: true when the textArea has some input.

Since the send button in this case isn't exposed as a view, you could create a property on the textArea:

textArea.sendButtonEnabled = true; // default
pec1985 commented 13 years ago

Will do, thanks for the idea!

sindresorhus commented 13 years ago

@pec1985 Is it possible to set a new it to "true" later on using the property, or do I have to use the method?

var conversationView = Ti.Pedro.createSMSView({
    sendButtonEnabled: false;
});

conversationView.addEventListener('change', function(e) {
    if ( e.value ) {
        e.source.sendButtonEnabled = true;
    } 
});

Also, "setSendButtonDissabled", disabled is with one "s".

pec1985 commented 13 years ago

Same thing, you can do "setSendButtonDissabled()" or ".sendButtonDissabled = "

But, does it matter?

sindresorhus commented 13 years ago

No, not really, I'm just not a fan of getters/setters.

pec1985 commented 12 years ago

Being a fan or not of getters and setters has nothing to do with the issue.

setSomething(x) and something = x is the same exact thing, so either way you are calling a setter, no way around this.

For example, to populate a tableView in Titanium:

tableView.setData( array );
// or
tableView.data = array;

Getters and Setters are fun

:)

pec1985 commented 12 years ago

Oh, and Dissabled is with one "s", thanks for that, oops

Fixed in 73685f3791