您好,我是用codeigniter。我用ajax 自动完成的jQuery 和的 jQuery的验证插件
有输入框被称为城市
<输入类型=文本级=城市NAME =城市值=>
我使用自动完成该输入框
jQuery的code
VAR一个= JQ('城市')。自动完成({
的serviceUrl:&LT ;?回声$这个 - > config->项目('BASE_URL');>家用/认证/ city_autocomplete?,
});
这个形象
当我从下拉jquery的验证插件选择一个值给出了一个错误,最小长度3。 但这个城市的名字是大于3 charactors
这是我的验证插件code
变种X = JQ(#CONTACTINFO)。验证({
规则:{
市: {
需要:{
依赖:函数(){
返回((类型==单店和放大器;地点)||(类型==连锁放;场地)||(类型==百货));
}
},
MINLENGTH:3,
最大长度:50
},
},
消息:{
市: {
要求:入市,
MINLENGTH:最小长度3
},
}
});
tihs是错误的图像
为什么会这样。如何避免这种情况,我累soooooooooooo辛苦,大约一个星期要弄清楚发生了什么,但不能。请帮忙 .......................... 谢谢verymuch。
更新
这是城市,州和邮编code HTML。州和邮编code是领域的下一个城市字段
< DIV CLASS =输入容器>
< DIV CLASS =catergory标题-C>
<跨度类=verdana12gray>< / SPAN>
< / DIV>
< DIV CLASS =表单项>
< DIV CLASS =catergory-输入-B>
< DIV CLASS =输入小>
<输入
类=城市明确输入
的id =textarea_small_1
值=<如果PHP(使用isset($城市['值'])){回声$城市['值'];}其他{回声$地图['等'] ['城市名'];}?&GT ;
类型=文本
NAME =城
/>
< / DIV>
< DIV CLASS =输入小>
<输入
类=国家明确输入
的id =textarea_small_2
值=<如果PHP(使用isset($状态['值'])){回声$状态['值'];}>?
类型=文本
NAME =状态
/>
< / DIV>
< DIV CLASS =输入小>
<输入类型=文本ID =textarea_small_3NAME =zip_ code
值=<如果PHP(使用isset($ zip_ code ['值'])){回声$ zip_ code ['值'];}>? />
< / DIV>
< / DIV>
< / DIV>
< DIV CLASS =清除修复>< / DIV>
< / DIV>
解决方案
嗯,你有一个重复的ID在那里:
ID =textarea_small
有固定的上面,你会需要截取的验证事件,迫使它触发选择事件之后 - 与jQuery UI的自动完成,也就是pretty的方便即
...
选择:功能(事件,UI){
VAR了selectedValue = ui.item.value;
VAR focusedElement = $(本);
//我的pretend功能checkData或添加一个验证事件火在这里。
checkData(focusedElement,ui.item,了selectedValue);
返回false;
},
...
我不熟悉的插件,您正在使用,但它应该有类似的东西。
hi i am using codeigniter . i am using ajax autocomplete for jquery and jquery validation plugin
there is input box called city
<input type="text" class="city" name="city" value="">
i use autocomplete for this inputbox
jquery code
var a = jq('.city').autocomplete({
serviceUrl:"<? echo $this->config->item('base_url'); ?>home/auth/city_autocomplete",
});
image of this
when i select a value from the drop down the jquery validation plugin gives an error , 'min length 3'. but the city name is greater than 3 charactors
this is my validation plugin code
var x=jq("#contactinfo").validate({
rules: {
city: {
required:{
depends: function(){
return ((type == "Single Store & Venue") || (type == "Chain Store & Venue")|| (type == "Department Store"));
}
},
minlength: 3,
maxlength: 50
},
},
messages: {
city: {
required: "Enter City",
minlength: "min length 3"
},
}
});
tihs is the error image
why is this happening . how to avoid this , i tired soooooooooooo hard , about one week to figure out what is happening but couldn't . please help .......................... thank you verymuch .
UPDATE
this is city , state and zip code html . state and zipcode are the fields next to city field
<div class="input-container">
<div class="catergory-title-c">
<span class="verdana12gray"></span>
</div>
<div class="form-item">
<div class="catergory-inputs-b">
<div class="input-small">
<input
class="city clear-input"
id="textarea_small_1"
value="<?php if(isset($city['value'])){ echo $city['value'] ; }else{echo $map['other']['CityName'];} ?>"
type="text"
name="city"
/>
</div>
<div class="input-small">
<input
class="state clear-input"
id="textarea_small_2"
value="<?php if(isset($state['value'])){ echo $state['value'] ; } ?>"
type="text"
name="state"
/>
</div>
<div class="input-small">
<input type="text" id="textarea_small_3" name="zip_code"
value="<?php if(isset($zip_code['value'])){ echo $zip_code['value'] ; } ?>" />
</div>
</div>
</div>
<div class="clear-fix"></div>
</div>
解决方案
um you have a duplicate id IN THERE:
id="textarea_small"
Having fixed the above, you will need to intercept the validation event to force it to fire AFTER the selection event - with the jQuery UI Autocomplete, that is pretty easy ie
...
select: function(event, ui) {
var selectedValue = ui.item.value;
var focusedElement = $(this);
// my pretend function checkData OR add a validation event fire here.
checkData(focusedElement, ui.item, selectedValue);
return false;
},
...
I am not familiar with the plug-in you are using but it should have something like that.