Вопрос

I have an observable that contains two values. I want to enable a button if the input value is not empty. I check if the value is not empty with a function. Please help, here is a jsfiddle example of what I'm trying to achieve: http://jsfiddle.net/zNLNy/1213/.

Here is some code:

<div id="form">
    <input type="text" data-bind="value: message" />
    <button data-bind="enabled: canSend">Send</button>
</div>

var chatFormObservable = kendo.Observable({
    message: "",
    canSend: function(){
        return this.get("message") != ""
    }
});
kendo.bind($("#form"), chatFormObservable);
Это было полезно?

Решение

The function you need is "subscribe"; you need to subscribe to the input value and enable the button if a value is entered, else disable it:

self.message.subscribe(function (value) {

    if(value){
        self.canSend(true);
    } 
    else{
        self.canSend(false);
    }

});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top