Boa Tarde
Estou desenvolvendo uma pagina onde tem um combobox autocomplete através de jquery-ui. Para validar o mesmo estou utilizando o plugin Validation Engine. e estou tendo o seguinte problema:
Quando utilizo apenas um no html. para montar este combo… a validação funciona. mais quando utilizo do jquery. não valida o combobox. Preciso que ele seje requerido, não podendo ser em branco.
Para entendimento estou anexando o codigo do meu jsp.
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:import url="/layout/cabecalho.jsp" />
<style>
.ui-autocomplete {
max-height: 100px;
overflow-y: auto;
/* prevent horizontal scrollbar */
overflow-x: hidden;
/* add padding to account for vertical scrollbar */
padding-right: 20px;
}
/* IE 6 doesn't support max-height
* we use height instead, but this forces the menu to always be this tall
*/
* html .ui-autocomplete {
height: 100px;
}
</style>
<script type="text/javascript">
// <![CDATA[
$(function() {
var lnk = document.createElement('link');
lnk.setAttribute('type', "text/css" );
lnk.setAttribute('rel', "stylesheet" );
lnk.setAttribute('href', "form.css" );
document.getElementsByTagName("head").item(0).appendChild(lnk);
});
$(function(){
// Tabs
$('#tabs').tabs();
});
(function( $ ) {
$.widget( "ui.combobox", {
_create: function() {
var self = this,
select = this.element.hide(),
selected = select.children( ":selected" ),
value = selected.val() ? selected.text() : "";
var input = this.input = $( "<input>" )
.insertAfter( select )
.val( value )
.width(300)
.autocomplete({
delay: 0,
minLength: 0,
source: function( request, response ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
response( select.children( "option" ).map(function() {
var text = $( this ).text();
if (this.value && ( !request.term || matcher.test(text) ) )
return {
label: text.replace(
new RegExp(
"(?![^&;]+;)(?!<[^<>]*)(" +
$.ui.autocomplete.escapeRegex(request.term) +
")(?![^<>]*>)(?![^&;]+;)", "gi"
), "<strong>$1</strong>" ),
value: text,
option: this
};
}) );
},
select: function( event, ui ) {
ui.item.option.selected = true;
self._trigger( "selected", event, {
item: ui.item.option
});
},
change: function( event, ui ) {
if ( !ui.item ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
valid = false;
select.children( "option" ).each(function() {
if ( $( this ).text().match( matcher ) ) {
this.selected = valid = true;
return false;
}
});
if ( !valid ) {
// remove invalid value, as it didn't match anything
$( this ).val( "" );
select.val( "" );
input.data( "autocomplete" ).term = "";
return false;
}
}
}
})
.addClass( "ui-widget ui-widget-content" );
input.data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.label + "</a>" )
.appendTo( ul );
};
this.button = $( "<button type='button'> </button>" )
.attr( "tabIndex", -1 )
.attr( "title", "Mostra todos os itens" )
.insertAfter( input )
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass( "ui-corner-all" )
.addClass( "ui-button-icon" )
.click(function() {
// close if already visible
if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
input.autocomplete( "close" );
return;
}
// work around a bug (likely same cause as #5265)
$( this ).blur();
// pass empty string as value to search for, displaying all results
input.autocomplete( "search", "" );
input.focus();
});
},
destroy: function() {
this.input.remove();
this.button.remove();
this.element.show();
$.Widget.prototype.destroy.call( this );
}
});
})( jQuery );
$(function() {
$( "#filial" ).combobox();
$( "#toggle" ).click(function() {
$( "#filial" ).toggle();
});
});
$(function() {
$( "#datepicker" ).datepicker();
$( "#datepicker" ).datepicker( "option", "dateFormat", "mm/yy" );
$( "#datepicker" ).datepicker( "option", $.datepicker.regional[ "Portuguese (Português)" ]);
$( "#datepicker" ).datepicker( "option", "showAnim", "fold");
$( "#datepicker" ).datepicker( "option", "showOn", "button");
$( "#datepicker" ).datepicker( "option", "buttonImage", "/webdip/imagens/calendar.gif");
$( "#datepicker" ).datepicker( "option", "buttonImageOnly", "true");
$( "#dialog-sucess" ).dialog({autoOpen:false});
$( "#dialog-error" ).dialog({autoOpen:false});
});
$(document).ready(function(){
$("#form").validationEngine('attach');
});
$(document).ready(function(){
$("form").submit(function() {
if ($("#form").validationEngine('validate')) {
$.ajax({
type: "POST",
url: "<c:url value="/sped/gerarSped"/>",
data: $('#form').serialize(),
error: function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-error" ).dialog({
modal: true,
autoOpen: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
},
success: function() {
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-sucess" ).dialog({
modal: true,
autoOpen: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
var url = "<c:url value="/sped/gerar"/>";
$(location).attr('href',url);
}
}
});
}
});
}
return false;
});
});
</script>
<div id="tabs">
<ul>
<li><a href="#tabs-1">Sped</a></li>
</ul>
<div id="tabs-1">
<form id="form" action="">
<label for="datepicker">Data do mês:</label></br>
<input type="text" id="datepicker" name="periodo" size="30" class="validate[required,custom[mesano]]" /></br></br>
<label for="filial">Filial:</label></br>
//este não valida, pois utilizo ele com jquery
<select id="filial" name="sufixoCNPJ", class="validate[required]">
<c:forEach items="${empresaFilialList}" var="empresas">
<option value=${empresas.sufixoCNPJ}>${empresas.sufixoCNPJ} - ${empresas.nome}</option>
</c:forEach>
</select>
</br></br>
<button type="submit"><img src="<c:url value="/imagens/formulario_icone_gerar.png"/>" alt="submit" class="iconegerar" /><p>Gerar</p></button>
</form>
</div>
</div>
</div>
<div id="dialog-sucess" title="Requisição efetuada">
<p>
<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
<b>Sua requisição para geração do Sped Fiscal foi efetuada.</b>
</p>
<p>
Verifique e faça download do arquivo pelo acompanhamento de requisições.
</p>
</div>
<div id="dialog-error" title="Requisição não efetuada">
<p>
<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
<b>Sua requisição para geração do Sped Fiscal não foi efetuada.</b>
</p>
<p>
Favor tentar novamente. Se persistir o erro favor entrar em contato com Departamento de TI.
</p>
</div>
<c:import url="/layout/rodape.jsp" />
Alguem conhece ou já enfrentou este problema.
Muito Obrigado