3

I have the following custom binding

ko.bindingHandlers.dialogFor = { init: function(el, valueAccessor) { $(el).dialog(); var val = valueAccessor(); if(ko.isObservable(val)) $(el).on('dialogclose', function(){ val(null) }); } }; 

This allows me to tag an html fragment with a dialogFor binding and open dialogs simply by setting observables.

Unfortunately, the value that gets passed in is always unwrapped so the if check never passes and resetting the observable on dialog close doesn't work.

How do I get the actual observable that was passed, not just the unwrapped value?

1 Answer 1

1

I can't see your HTML so its a guess, i think you are using observable in your custom binding's value like :

 <div data-bind="dialogFor: val()"></div> 

if yes than you already unwrapped the value and only value not the observable is passing to your custom binding, so that's why your if condition is failing.You should use it like :

 <div data-bind="dialogFor: val"></div> 

I have created a working example in which jquery ui dialog state is controlling by observable.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.