0

I am trying to use Knockout Validation in combination with Bootstrap Combobox Plugin.

I have a select control that is bound to my observable property which has the required attribute (for KO Validation).

 <select data-bind="attr: { options: TypeAheadSource, value: XYZ, validationOptions: {errorElementClass: 'input-validation-error'}, typeaheadCombobox: {}"></select>

I have a custom binding associated with the select control in which I basically just call the Bootstrap Combobox Plugin. That creates a Div with an input control over the select control and hides the select control.

The knockout validation fires up when I dont select a value in the comobox and shows the error message next to the control BUT the field is not highlighted. Here is how it looks like

enter image description here

As you can see, the error message shows up but the input field is not highlighted.

Here is the final html that is generated when the validation fires.

    <div class="combobox-container">
    <input style="position:static;" type="text" autocomplete="off" data-bind="{ value: Name, validationOptions: { errorElementClass: 'input-validation-error' }" class="input-large">
<span class="add-on btn dropdown-toggle" data-dropdown="dropdown"><span class="caret"></span>
<span class="combobox-clear"><i class="icon-remove"></i></span></span>
<select data-bind="validationOptions: { errorElementClass: 'input-validation-error' }, options: TypeAheadSource, value: Name, typeaheadSimpleCombobox: { }" class="combobox input-validation-error"></select>
    </div>

As you can see, the select control (which was hidden by the plugin) gets the validation error class I defined ('input-validation-error') but the input control created by the plugin does not. That is the main issue here.

So, I thought it could be becasue the input control is not directly bound to the property. So, I tried adding the same value binding as the select control to the input control created by the plugin inside the custom binding. I also added the validationOptions binding. These changes didnt work either.

Strange thing is I also have a typeahead textbox bound to another property which uses a similar design (custom binding to create the typeahead plugin over an input control) and the validation + highlighting works perfectly on that. Here is the final html from that.

<input type="text" data-bind="value: xyz, validationOptions: { errorElementClass: 'input-validation-error' }, typeaheadTextBox: { source: $data.TypeAheadSource }" class="typeaheadValue input-mini" data-provide="customtypeahead" autocomplete="off">

Could someone tell me if I am missing any additional steps. I am sure you might need more details. Please leave a comment and I will try to add more details.

Thanks.

4

1 回答 1

0

我想通了这个问题。如果有人有同样的问题,这就是我所做的。尽管我在插件创建的输入控件上设置了值绑定,但绑定是在创建控件之前应用的,因此,我必须专门在插件创建的输入控件上重新应用绑定。这对我有用。

于 2013-05-20T18:28:32.587 回答