I have a custom binding for autocomplete processing, and when a user selects an element from autocomplete, I communicate with the server and replace the text field with the abbreviated name. The problem is that the second time it calls the "update" function of my user binding.
Knockout.js code (edit: note the following: CoffeeScript):
ko.bindingHandlers.ko_autocomplete =
init: (element, params) ->
$(element).autocomplete(params())
update: (element, valueAccessor, allBindingsAccessor, viewModel) ->
unless task.name() == undefined
$.ajax "/tasks/name",
data: "name=" + task.name(),
success: (data,textStatus, jqXHR) ->
task.name(data.short_name)
Task = ->
@name = ko.observable()
@name_select = (event, ui) ->
task.name(ui.item.name)
false
task = Task.new()
View
= f.text_field :name, "data-bind" => "value: name, ko_autocomplete: { source: '/autocomplete/tasks', select: name_select }"
Is there a way to apply a choke to user binding?
I just want the "update" function of custom bindings to run the second time I set task.name to the short name sent from the server.
source
share