How to disable All child Controls in a div with the help of KnockoutJS

2,932 views
Skip to first unread message

sudhans...@gmail.com

unread,
Jul 10, 2013, 5:38:46 AM7/10/13
to knock...@googlegroups.com
How to disable All child Controls in a div with the help of Knockout JS

Patrick Steele

unread,
Jul 10, 2013, 8:10:12 AM7/10/13
to knock...@googlegroups.com
You could create a custom binding handler that would add/remove the "disabled" attribute on a set of elements.  Here's a quick sample I threw together:

ko.bindingHandlers.toggleAll = {
    update: function(element, valueAccessor, allBindingsAccessor) {
        var aa = allBindingsAccessor();
        var selector = aa.selector;
        var va = valueAccessor();
        var value = ko.utils.unwrapObservable(va);
        if( value )
        {
            $(selector).children().removeAttr('disabled');
        }
        else
        {
            $(selector).children().attr('disabled', 'disabled');
        }
    }
};

Here's the jsFiddle showing how it works:

http://jsfiddle.net/psteele/bde8H/

On Wed, Jul 10, 2013 at 5:38 AM, <sudhans...@gmail.com> wrote:
How to disable All child Controls in a div with the help of Knockout JS

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sudhanshu Shukla

unread,
Jul 10, 2013, 8:54:53 AM7/10/13
to knock...@googlegroups.com
Thanks Patrick for Replay.

But I have only sever side controls in that Div, which I want to disable.


--
You received this message because you are subscribed to a topic in the Google Groups "KnockoutJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/knockoutjs/iTLIQnZwigE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to knockoutjs+...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks & Regards,
Sudhanshu Shukla

Patrick Steele

unread,
Jul 10, 2013, 8:57:05 AM7/10/13
to knock...@googlegroups.com
How would you disable them without knockout?  What's the technology behind these server side controls?
Reply all
Reply to author
Forward
0 new messages