Skip to content

Commit 279c195

Browse files
committed
fixed bug in suggest script
1 parent 3f364f5 commit 279c195

File tree

9 files changed

+64
-47
lines changed

9 files changed

+64
-47
lines changed

form-validator/date.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* @license Dual licensed under the MIT or GPL Version 2 licenses
15-
* @version 1.9.27
15+
* @version 1.9.29
1616
*/
1717
(function($) {
1818

form-validator/jquery.form-validator.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Documentation and issue tracking on Github <https://github.com/victorjonsson/jQuery-Form-Validator/>
66
*
77
* @license Dual licensed under the MIT or GPL Version 2 licenses
8-
* @version 1.9.27
8+
* @version 1.9.29
99
*/
1010
(function($) {
1111

@@ -362,12 +362,14 @@
362362
* @returns {jQuery}
363363
*/
364364
$.fn.addSuggestions = function(settings) {
365+
var sugs = false;
365366
this.find('input').each(function() {
366-
var $input = $(this),
367-
suggestions = $input.attr('data-suggestions');
367+
var $field = $(this);
368368

369-
if( suggestions && suggestions.length ) {
370-
$.formUtils.suggest($input, $.split(suggestions), settings);
369+
sugs = $.split($field.attr('data-suggestions'));
370+
371+
if( sugs.length > 0 ) {
372+
new $.formUtils.suggest($field, sugs, settings);
371373
}
372374
});
373375
return this;
@@ -542,11 +544,10 @@
542544
var findScriptPathAndLoadModules = function() {
543545
var foundPath = false;
544546
$('script').each(function() {
545-
var src = $(this).attr('src');
546-
if( src ) {
547-
var scriptName = src.substr(src.lastIndexOf('/')+1, src.length);
547+
if( this.src ) {
548+
var scriptName = this.src.substr(this.src.lastIndexOf('/')+1, this.src.length);
548549
if(scriptName.indexOf('jquery.form-validator.js') > -1 || scriptName.indexOf('jquery.form-validator.min.js') > -1) {
549-
foundPath = src.substr(0, src.lastIndexOf('/')) + '/';
550+
foundPath = this.src.substr(0, this.src.lastIndexOf('/')) + '/';
550551
if( foundPath == '/' )
551552
foundPath = '';
552553
return false;
@@ -817,7 +818,7 @@
817818
cursor: 'pointer'
818819
},
819820
activeSuggestionCSS : {
820-
background : '#F2F2F2'
821+
background : '#E9E9E9'
821822
}
822823
};
823824

@@ -838,6 +839,7 @@
838839
};
839840

840841
$element
842+
.data('suggestions', suggestions)
841843
.valAttr('suggestion-nr', this._numSuggestionElements)
842844
.bind('focus', function() {
843845
$(this).trigger('keyup');
@@ -861,16 +863,17 @@
861863

862864
// Find the right suggestions
863865
if(val != '') {
864-
var findPartials = val.length > 2 ? true:false;
865-
$.each(suggestions, function(i, v) {
866-
v = v.toLocaleLowerCase();
867-
if(v.indexOf(val) === 0 || (findPartials && v.indexOf(val) > -1)) {
868-
foundSuggestions.push(v);
866+
var findPartial = val.length > 2;
867+
$.each($input.data('suggestions'), function(i, suggestion) {
868+
var lowerCaseVal = suggestion.toLocaleLowerCase();
869+
if( lowerCaseVal == val ) {
870+
foundSuggestions.push('<strong>'+suggestion+'</strong>');
871+
hasTypedSuggestion = true;
872+
return false;
873+
} else if(lowerCaseVal.indexOf(val) === 0 || (findPartial && lowerCaseVal.indexOf(val) > -1)) {
874+
foundSuggestions.push(suggestion.replace(new RegExp(val, 'gi'), '<strong>$&</strong>'));
869875
}
870876
});
871-
872-
if(foundSuggestions.length == 1 && foundSuggestions[0].length == val.length)
873-
hasTypedSuggestion = true;
874877
}
875878

876879
// Hide suggestion container
@@ -903,9 +906,14 @@
903906

904907
// Add suggestions HTML to container
905908
$suggestionContainer.html('');
906-
$.each(foundSuggestions, function(i, s) {
909+
$.each(foundSuggestions, function(i, text) {
907910
$('<div></div>')
908-
.text(s)
911+
.append(text)
912+
.css({
913+
overflow: 'hidden',
914+
textOverflow : 'ellipsis',
915+
whiteSpace : 'nowrap'
916+
})
909917
.addClass('form-suggest-element')
910918
.appendTo($suggestionContainer)
911919
.click(function() {

form-validator/jquery.form-validator.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/location.dev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* @license Dual licensed under the MIT or GPL Version 2 licenses
14-
* @version 1.9.27
14+
* @version 1.9.29
1515
*/
1616
(function($) {
1717

@@ -23,7 +23,7 @@
2323
validate : function(str) {
2424
return $.inArray(str.toLowerCase(), this.countries) > -1;
2525
},
26-
countries : ['afghanistan','albania','algeria','american samoa','andorra','angola','anguilla','antarctica','antigua and barbuda','arctic ocean','argentina','armenia','aruba','ashmore and cartier islands','atlantic ocean','australia','austria','azerbaijan','bahamas','bahrain','baltic sea','baker island','bangladesh','barbados','bassas da india','belarus','belgium','belize','benin','bermuda','bhutan','bolivia','borneo','bosnia and herzegovina','botswana','bouvet island','brazil','british virgin islands','brunei','bulgaria','burkina faso','burundi','cambodia','cameroon','canada','cape verde','cayman islands','central african republic','chad','chile','china','christmas island','clipperton island','cocos islands','colombia','comoros','cook islands','coral sea islands','costa rica','croatia','cuba','cyprus','czech republic','democratic republic of the congo','denmark','djibouti','dominica','dominican republic','east timor','ecuador','egypt','el salvador','equatorial guinea','eritrea','estonia','ethiopia','europa island','falkland islands (islas malvinas)','faroe islands','fiji','finland','france','french guiana','french polynesia','french southern and antarctic lands','gabon','gambia','gaza strip','georgia','germany','ghana','gibraltar','glorioso islands','greece','greenland','grenada','guadeloupe','guam','guatemala','guernsey','guinea','guinea-bissau','guyana','haiti','heard island and mcdonald islands','honduras','hong kong','howland island','hungary','iceland','india','indian ocean','indonesia','iran','iraq','ireland','isle of man','israel','italy','jamaica','jan mayen','japan','jarvis island','jersey','johnston atoll','jordan','juan de nova island','kazakhstan','kenya','kerguelen archipelago','kingman reef','kiribati','kosovo','kuwait','kyrgyzstan','laos','latvia','lebanon','lesotho','liberia','libya','liechtenstein','lithuania','luxembourg','macau','macedonia','madagascar','malawi','malaysia','maldives','mali','malta','marshall islands','martinique','mauritania','mauritius','mayotte','mediterranean sea','mexico','micronesia','midway islands','moldova','monaco','mongolia','montenegro','montserrat','morocco','mozambique','myanmar','namibia','nauru','navassa island','nepal','netherlands','netherlands antilles','new caledonia','new zealand','nicaragua','niger','nigeria','niue','norfolk island','north korea','north sea','northern mariana islands','norway','oman','pacific ocean','pakistan','palau','palmyra atoll','panama','papua new guinea','paracel islands','paraguay','peru','philippines','pitcairn islands','poland','portugal','puerto rico','qatar','republic of the congo','reunion','romania','ross sea','russia','rwanda','saint helena','saint kitts and nevis','saint lucia','saint pierre and miquelon','saint vincent and the grenadines','samoa','san marino','sao tome and principe','saudi arabia','senegal','serbia','seychelles','sierra leone','singapore','slovakia','slovenia','solomon islands','somalia','south africa','south georgia and the south sandwich islands','south korea','southern ocean','spain','spratly islands','sri lanka','sudan','suriname','svalbard','swaziland','sweden','switzerland','syria','taiwan','tajikistan','tanzania','tasman sea','thailand','togo','tokelau','tonga','trinidad and tobago','tromelin island','tunisia','turkey','turkmenistan','turks and caicos islands','tuvalu','uganda','ukraine','united arab emirates','united kingdom','uruguay','usa','uzbekistan','vanuatu','venezuela','viet nam','virgin islands','wake island','wallis and futuna','west bank','western sahara','yemen','zambia','zimbabwe'],
26+
countries : ['afghanistan','albania','algeria','american samoa','andorra','angola','anguilla','antarctica','antigua and barbuda','arctic ocean','argentina','armenia','aruba','ashmore and cartier islands','atlantic ocean','australia','austria','azerbaijan','bahamas','bahrain','baltic sea','baker island','bangladesh','barbados','bassas da india','belarus','belgium','belize','benin','bermuda','bhutan','bolivia','borneo','bosnia and herzegovina','botswana','bouvet island','brazil','british virgin islands','brunei','bulgaria','burkina faso','burundi','cambodia','cameroon','canada','cape verde','cayman islands','central african republic','chad','chile','china','christmas island','clipperton island','cocos islands','colombia','comoros','cook islands','coral sea islands','costa rica','croatia','cuba','cyprus','czech republic','democratic republic of the congo','denmark','djibouti','dominica','dominican republic','east timor','ecuador','egypt','el salvador','equatorial guinea','eritrea','estonia','ethiopia','europa island','falkland islands','faroe islands','fiji','finland','france','french guiana','french polynesia','french southern and antarctic lands','gabon','gambia','gaza strip','georgia','germany','ghana','gibraltar','glorioso islands','greece','greenland','grenada','guadeloupe','guam','guatemala','guernsey','guinea','guinea-bissau','guyana','haiti','heard island and mcdonald islands','honduras','hong kong','howland island','hungary','iceland','india','indian ocean','indonesia','iran','iraq','ireland','isle of man','israel','italy','jamaica','jan mayen','japan','jarvis island','jersey','johnston atoll','jordan','juan de nova island','kazakhstan','kenya','kerguelen archipelago','kingman reef','kiribati','kosovo','kuwait','kyrgyzstan','laos','latvia','lebanon','lesotho','liberia','libya','liechtenstein','lithuania','luxembourg','macau','macedonia','madagascar','malawi','malaysia','maldives','mali','malta','marshall islands','martinique','mauritania','mauritius','mayotte','mediterranean sea','mexico','micronesia','midway islands','moldova','monaco','mongolia','montenegro','montserrat','morocco','mozambique','myanmar','namibia','nauru','navassa island','nepal','netherlands','netherlands antilles','new caledonia','new zealand','nicaragua','niger','nigeria','niue','norfolk island','north korea','north sea','northern mariana islands','norway','oman','pacific ocean','pakistan','palau','palmyra atoll','panama','papua new guinea','paracel islands','paraguay','peru','philippines','pitcairn islands','poland','portugal','puerto rico','qatar','republic of the congo','reunion','romania','ross sea','russia','rwanda','saint helena','saint kitts and nevis','saint lucia','saint pierre and miquelon','saint vincent and the grenadines','samoa','san marino','sao tome and principe','saudi arabia','senegal','serbia','seychelles','sierra leone','singapore','slovakia','slovenia','solomon islands','somalia','south africa','south georgia and the south sandwich islands','south korea','southern ocean','spain','spratly islands','sri lanka','sudan','suriname','svalbard','swaziland','sweden','switzerland','syria','taiwan','tajikistan','tanzania','tasman sea','thailand','togo','tokelau','tonga','trinidad and tobago','tromelin island','tunisia','turkey','turkmenistan','turks and caicos islands','tuvalu','uganda','ukraine','united arab emirates','united kingdom','uruguay','usa','uzbekistan','vanuatu','venezuela','viet nam','virgin islands','wake island','wallis and futuna','west bank','western sahara','yemen','zambia','zimbabwe'],
2727
errorMessage : '',
2828
errorMessageKey: 'badCustomVal'
2929
});

0 commit comments

Comments
 (0)