Skip to content

Commit a54d1be

Browse files
committed
dynamic multiple input size
value not being removed on multiple values setup
1 parent 21cdbaa commit a54d1be

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

jquery.flexdatalist.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* jQuery Flexdatalist basic stylesheet.
3+
*
4+
* Version:
5+
* 2.2.1
6+
*
7+
* Github:
8+
* https://github.com/sergiodlopes/jquery-flexdatalist/
9+
*
10+
*/
111
.flexdatalist-results {
212
position: absolute;
313
top: 0;
@@ -86,7 +96,7 @@
8696
.flexdatalist-multiple li.input-container,
8797
.flexdatalist-multiple li.input-container input {
8898
border: none;
89-
width: 280px;
99+
width: 40px;
90100
height: auto;
91101
padding: 0 0 0 4px;
92102
line-height: 24px;

jquery.flexdatalist.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Autocomplete input fields, with support for datalists.
44
*
55
* Version:
6-
* 2.2.0.1
6+
* 2.2.1
77
*
88
* Depends:
99
* jquery.js > 1.8.3
@@ -172,6 +172,7 @@ jQuery.fn.flexdatalist = function (_option, _value) {
172172
_this.action.showAllResults(event);
173173
_this.action.clearValue(event);
174174
_this.action.removeResults(event);
175+
_this.action.inputWidth(event);
175176
})
176177
// Focusout
177178
.on('focusout', function (event) {
@@ -299,6 +300,23 @@ jQuery.fn.flexdatalist = function (_option, _value) {
299300
});
300301
}
301302
},
303+
/**
304+
* Calculate input width by number of characters.
305+
*/
306+
inputWidth: function (event) {
307+
var options = _this.options.get();
308+
if (options.multiple) {
309+
var keyword = $alias.val(),
310+
fontSize = parseInt($alias.css('fontSize').replace('px', '')),
311+
minWidth = 40,
312+
maxWidth = $this.innerWidth(),
313+
width = ((keyword.length + 1) * fontSize);
314+
315+
if (width >= minWidth && width <= maxWidth) {
316+
$alias[0].style.width = width + 'px';
317+
}
318+
}
319+
},
302320
/**
303321
* Clear text/alias input when criteria is met.
304322
*/
@@ -624,7 +642,7 @@ jQuery.fn.flexdatalist = function (_option, _value) {
624642
_multiple.toggle($(this));
625643
// Remove
626644
}).find('.fdl-remove').click(function () {
627-
_multiple.remove($(this).parent());
645+
_this.fvalue.remove($(this).parent());
628646
});
629647

630648
this.push(val);

jquery.flexdatalist.min.css

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

0 commit comments

Comments
 (0)