0

I am currently using the validation plugin from https://github.com/ericmbarnard/Knockout-Validation and it is working nicely on plain value fields such as input boxes, but I can not get any validation messages to appear on typeahead fields.

The observable that the typeahead is assigned to has a required validation rule assigned to it, and the plugin can validate it, e.g. when it is blank calling isValid() returns false, but the validation message is not showing.

My typeahead custom binding is as follows:

ko.bindingHandlers.typeahead =
init: (element, valueAccessor) ->
    binding = this
    elem = $(element)
    value = valueAccessor()
    elem.typeahead(
        source: ->
            ko.utils.unwrapObservable(value.source)
        onselect: (val) ->
            value.target val
        )

    elem.change ->
        value.target elem.val()

update: (element, valueAccessor) ->
    elem = $(element)
    value = valueAccessor()
    elem.val value.target()

and is used like:

<input type="text" data-provide="typeahead" data-items="4" data-bind="typeahead:  { target: selectedValue, source: sourceValues}" />

One post on the github issues suggests pasting in ko.bindingHandlers.validationCore.init(element, valueAccessor) at the end of the init section of the binding, but this has not seemed to help anything

Thewads
  • 4,953
  • 11
  • 55
  • 71
  • I can make it work by adding in a value binding into the input, but that seems kind of weird to do – Thewads Dec 12 '12 at 13:32
  • I used ko.bindingHandlers.validationCore.init for a custom binding and it works, try to debug the init method and see whats going on, it should inject the span using var validationMessageElement = exports.insertValidationMessage(element); – Anders Dec 12 '12 at 15:26

0 Answers0