JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" href="http://www.jeasyui.com/easyui/themes/icon.css">
<script src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<div>
<span>Enter color: <input id="colorCB" type="text"></span>
<span>Enter size: <input id="sizeCB" type="text"></span>
</div>
JavaScript
var colorData = [{value: '0',text: 'red'},
{value: '1',text: 'yellow'},
{value: '2',text: 'green'}];
var sizeData = [{value: '0',text: 'Small'},
{value: '1',text: 'Medium'},
{value: '2',text: 'Large'},
{value: '4',text: 'XL'},
{value: '5',text: 'XXL'}];
$(function() {
$('#colorCB').combobox({ width: 150, panelWidth:150, data: colorData, value: '1' });
$('#sizeCB').combobox({ width: 150, panelWidth:150, data: sizeData, value: '2' });
// bind focus listener to comboboxes
$('#colorCB').combobox('textbox').bind('focus', function(){
$('#colorCB').combobox('showPanel');
});
$('#sizeCB').combobox('textbox').bind('focus', function(){
$('#sizeCB').combobox('showPanel');
});
// bind blur listener to comboboxes
$('#colorCB').combobox('textbox').bind('blur', function(){
comboOnBlur($('#colorCB'));
});
$('#sizeCB').combobox('textbox').bind('blur', function(){
comboOnBlur($('#sizeCB'));
});
// process onBlur for the given combobox
function comboOnBlur(cb) {
console.log('onBlur called for cb:'+cb.attr('id'));
if(isComboboxSelectionValid(cb)) {
console.log('isComboboxSelectionValid for cb:'+cb.attr('id'));
// send selected combo data to server...
}
}
// validate combobox selection
function isComboboxSelectionValid(cb) {
var value = cb.combobox('getText');
if (value) {
var opts = cb.combobox('options');
var data = cb.combobox('getData');
for (var i = 0; i < data.length; i++) {
if (value == data[i][opts.textField]) {
return true;
}
}
cb.combobox('textbox').addClass("validatebox-invalid");
$.messager.alert('Invalid selection', 'Please enter a valid value!', "error", function() {
cb.combobox('textbox').removeClass("validatebox-invalid");
cb.combobox('reset');
});
return false;
}
return true;
}
});