Questions tagged [ko-custom-binding]

Use this tag for question regarding the creation or use of Knockout js custom bindings

Knockout custom bindings allow to encapsulate behaviors that control the interaction between DOM elements, and bound observables.

This gives a lot of flexibility to encapsulate sophisticated behaviors in an easy-to-reuse way, for example grids.

Custom bindings can also be used to allow to bind components and behaviours existing in other libraries like jQuery, jQuery plugins, or jQuery UI.

This is the official documentation on Creating custom bindings.

39 questions
8
votes
1 answer

How to use custom binding with ko.observableArray()

How does knockout custom binding work with observableArray? When using ko.observable() with custom binding, everything works as expected. When using ko.observableArray(), only the initial events (init and update once) are thrown, but further changes…
Dresel
  • 2,375
  • 1
  • 28
  • 44
5
votes
1 answer

Knockout: how to update another binding from custom binding?

We have usual problem with optionsCaption binding: it is always showed even when there is only one element. We solved this problem using our custom binding: ko.bindingHandlers.optionsAutoSelect = { update: function (element, valueAccessor,…
Yauhen.F
  • 2,382
  • 3
  • 19
  • 25
5
votes
2 answers

Knockout.js - how do I throttle custom bindings

I've got a custom binding to handle autocomplete, and when a user selects an item from the autocomplete I talk to the server and replace the text_field with a shortened name. The problem is that this triggers the 'update' function of my custom…
map7
  • 5,096
  • 6
  • 65
  • 128
4
votes
1 answer

Extending an observable in a custom binding

I have a custom binding handler that I am binding to a complex object in my view model. The binding handler works correctly and the update function is called when any of the observable's properties update. However, the update function is called for…
Steve
  • 9,335
  • 10
  • 49
  • 81
4
votes
1 answer

Custom binding handler, render binding from string template

I making a custom binding with a row template that should be optional. If the user does not supply a template id i want to use a default one, but it does not reside in a script tag in body, it's just a string on the options literal. How can i use a…
Anders
  • 17,306
  • 10
  • 76
  • 144
3
votes
1 answer

knockout custom binding for slick js not working

My working code without knockout binding is :

Slide 1

Irfan Y
  • 1,242
  • 2
  • 21
  • 68
3
votes
1 answer

Slick.js carousel with Knockout custom binding

I wanted to use the awesome slick carousel (http://kenwheeler.github.io/slick/) with Knockout. After looking at some of the other questions (https://stackoverflow.com/questions/26368176/slick-js-carousel-not-working-with-knockout-template-binding)…
A Hsu
  • 33
  • 1
  • 6
3
votes
1 answer

Pass custom binding's value to DOM element added in custom binding

I am trying to use knockoutjs custom binding to create a component. This might not be a good idea and if there are other way to do the same thing, I am open to alternatives. The idea is to set a custom binding to an element so the element content…
Manuel Darveau
  • 4,585
  • 5
  • 26
  • 36
3
votes
2 answers

knockout: add another binding in a custom binding init

I want to create a custom binding as a shorthand for adding other bindings -- like a macro.
should do the same thing as
Something…
Sixtease
  • 790
  • 8
  • 18
2
votes
1 answer

What is Knockout custom binding "after" variable?

I am using knockout with ASP.NET MVC for some project. I am using the following bindingHandler of knockout ko.bindingHandlers.select2 = { after: ["options", "value", "selectedOptions"], init: function (el, valueAccessor,…
Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
2
votes
1 answer

Knockoutjs Radio Button Group Custom Binding Not Updating on Selection

I'm trying to create a custom binding in knockout that functions like the options default binding handler but uses radio buttons instead of a dropdown. Adding an item to the array will notify the update but selecting a different radio button will…
christo8989
  • 6,442
  • 5
  • 37
  • 43
2
votes
1 answer

Dispose event for knockoutjs custom binding

I am trying to develop a widget using knockoutjs custom binding. The widget would subscribe to an observable for the logged in user, so that its UI would change when a user logs in/out. I figured out that the subscribing has to be done in the init…
Sanjay
  • 8,755
  • 7
  • 46
  • 62
2
votes
1 answer

Knockout custom bindings wrapper with "options" binding

I am trying to make a simple KO custom bindings wrapper for the "options" binding similar to what is described in this example. My goal is to have a custom binding that will apply select2.js to the specified select box. I am trying to get started…
Bradley Trager
  • 3,570
  • 3
  • 26
  • 33
2
votes
2 answers

Custom binding valueAccessor has unexpected result

I am stumped by the following behavior in a custom binding of knockout.js: ko.bindingHandlers.customBinding = { update: function(element, valueAccessor, allBindingsAccessor) { var value = ko.utils.unwrapObservable(valueAccessor()); …
Tomalak
  • 332,285
  • 67
  • 532
  • 628
2
votes
1 answer

Custom binding, with binding & init - knockout.js

We're using knockout for a SPA consisting of multiple view models, to handle what view be visible we have wrapped the divs where we bind the 'sub' view models in with bindings. The problem we're seeing is that when a views visibility is toggled,…
Fredrik Leijon
  • 2,792
  • 18
  • 20
1
2 3