Skip to content

Commit

Permalink
Merge pull request #41 from SengitU/master
Browse files Browse the repository at this point in the history
Bug fixes related to multiple displays
  • Loading branch information
bcinarli authored Oct 24, 2016
2 parents b1fe43c + 3a9d6d0 commit 253167a
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 38 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uxrocket.select",
"version": "3.5.6",
"version": "3.5.7",
"homepage": "https://github.com/uxrocket/uxrocket.select",
"authors": [
"Bilal Çınarlı <[email protected]>"
Expand Down
41 changes: 29 additions & 12 deletions dist/uxrocket.select.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@
return false;
}

// Removes selected from a pre-loaded option
$(_this.optionData).each(function(){
if(this.text === $(e.target).parent().data('value')) {
this.selected = false;
}
});

_this.removeTag($(this).parent());
})
.parent()
Expand Down Expand Up @@ -512,7 +519,7 @@
this.$list.find('.' + highlight).removeClass(highlight);
this.$list.find('.' + selected).removeClass(selected);
this.$selection.find('.' + selectionText).text(text);
this.$el.find('option:eq(' + index + ')').prop('selected', true);
this.$el.find('[value="' + value + '"]').prop('selected', true);
this.onBlur();
this.$list.find('#' + optionID).addClass(selected);

Expand All @@ -527,7 +534,7 @@
else {
// double click deselects
if($option.hasClass(selected)) {
this.deSelect(index);
this.deSelect(value);
}

else {
Expand All @@ -536,7 +543,7 @@
return;
}

this.$el.find('option:eq(' + index + ')').prop('selected', true);
this.$el.find('[value="' + value + '"]').prop('selected', true);
$option.addClass(selected);

if(this.options.displayType === 'tags') {
Expand Down Expand Up @@ -568,26 +575,32 @@
this.emitEvent('change');
};

Select.prototype.deSelect = function(index) {
Select.prototype.deSelect = function(value) {
var selected = utils.getClassname('selected'),
selectionText = utils.getClassname('selectionText'),
selectionTag = utils.getClassname('selectionTag');
selectionTag = utils.getClassname('selectionTag'),
option = $('[data-value="' + value + '"]').parent();

if(!this.$drop) {
this.prepareDrop();
} else {
this.$drop.find('[data-value="' + value + '"]').parent().removeClass(selected)
}

this.$el.find('option:eq(' + index + ')').prop('selected', false);
this.$drop.find('#' + utils.getClassname('option') + '-' + index).removeClass(selected);
this.$selection.find('.' + selectionTag + '-' + index).remove();
this.$el.find('[value="' + value + '"]').removeAttr('selected');
option.removeClass(selected);
this.$selection.find('[data-value="' + value + '"]').remove();
this.$el.val($.grep(this.$el.val(), function(val) {
return val !== value;
}));

if(this.multiple && this.options.displayType !== 'tags' && this.$el.val() !== null) {
this.$selection
.find('.' + selectionText)
.html(this.options.multipleInfoMessage + ' ' + this.$el.val().length + '/' + this.optionData.length);
}

if(this.$el.val() === null) {
if(this.multiple && this.options.displayType === 'tags' && this.$el.val().length < 1) {
this.$selection.find('.' + selectionText).text(this.multiplePlaceholder);
}

Expand All @@ -596,7 +609,7 @@
};

Select.prototype.removeTag = function($tag) {
this.deSelect($tag.data('index'));
this.deSelect($tag.data('value'));
this.setDropPosition();
};

Expand Down Expand Up @@ -722,7 +735,11 @@
this.multiplePlaceholder = this.$el.attr('placeholder') || this.options.placeholder || '';

if(this.getSelected().length > 0) {
data.selectionText = this.renderSelectionTags();
if(this.options.displayType === 'text') {
data.selectionText = this.options.multipleInfoMessage + ' ' + this.getSelected().length + '/' + this.optionData.length;
} else {
data.selectionText = this.renderSelectionTags();
}
}
else {
data.selectionText = this.multiplePlaceholder;
Expand Down Expand Up @@ -1142,7 +1159,7 @@
});

// version
ux.version = '3.5.6';
ux.version = '3.5.7';

// default settings
ux.settings = defaults;
Expand Down
4 changes: 2 additions & 2 deletions dist/uxrocket.select.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/uxrocket.select.min.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3269,10 +3269,10 @@
</p>

<p class="wrap">
<select id="multiple" class="select" multiple placeholder="Display selection as text" data-multiple-info-message="Selected record:" data-display-type="text" data-max-selection="6">
<select id="multiple-record-number" class="select" multiple placeholder="Display selection as text" data-multiple-info-message="Selected record:" data-display-type="text" data-max-selection="6">
<optgroup label="A">
<option value="Adana">Adana</option>
<option value="Adıyaman">Adıyaman</option>
<option selected value="Adana">Adana</option>
<option selected value="Adıyaman">Adıyaman</option>
<option value="Afyon">Afyon</option>
<option value="Ağrı">Ağrı</option>
<option value="Aksaray">Aksaray</option>
Expand Down Expand Up @@ -3359,7 +3359,7 @@
</p>

<p class="wrap">
<select id="multiple" class="select" multiple placeholder="Display selection as tags" data-display-type="tags" data-max-selection="6">
<select id="multiple-tag-display" class="select" multiple placeholder="Display selection as tags" data-display-type="tags" data-max-selection="6">
<optgroup label="A">
<option value="Adana">Adana</option>
<option value="Adıyaman">Adıyaman</option>
Expand Down Expand Up @@ -3395,7 +3395,7 @@
<option value="Elazığ">Elazığ</option>
<option value="Erzincan">Erzincan</option>
<option value="Erzurum">Erzurum</option>
<option value="Eskişehir">Eskişehir</option>
<option selected value="Eskişehir">Eskişehir</option>
<option value="Gaziantep">Gaziantep</option>
<option value="Giresun">Giresun</option>
<option value="Gümüşhane">Gümüşhane</option>
Expand All @@ -3404,7 +3404,7 @@
<option value="Iğdır">Iğdır</option>
<option value="Isparta">Isparta</option>
<option value="İstanbul">İstanbul</option>
<option value="İzmir">İzmir</option>
<option selected value="İzmir">İzmir</option>
<option value="Kahramanmaraş">Kahramanmaraş</option>
<option value="Karabük">Karabük</option>
<option value="Karaman">Karaman</option>
Expand Down
41 changes: 29 additions & 12 deletions lib/uxrocket.select.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@
return false;
}

// Removes selected from a pre-loaded option
$(_this.optionData).each(function(){
if(this.text === $(e.target).parent().data('value')) {
this.selected = false;
}
});

_this.removeTag($(this).parent());
})
.parent()
Expand Down Expand Up @@ -512,7 +519,7 @@
this.$list.find('.' + highlight).removeClass(highlight);
this.$list.find('.' + selected).removeClass(selected);
this.$selection.find('.' + selectionText).text(text);
this.$el.find('option:eq(' + index + ')').prop('selected', true);
this.$el.find('[value="' + value + '"]').prop('selected', true);
this.onBlur();
this.$list.find('#' + optionID).addClass(selected);

Expand All @@ -527,7 +534,7 @@
else {
// double click deselects
if($option.hasClass(selected)) {
this.deSelect(index);
this.deSelect(value);
}

else {
Expand All @@ -536,7 +543,7 @@
return;
}

this.$el.find('option:eq(' + index + ')').prop('selected', true);
this.$el.find('[value="' + value + '"]').prop('selected', true);
$option.addClass(selected);

if(this.options.displayType === 'tags') {
Expand Down Expand Up @@ -568,26 +575,32 @@
this.emitEvent('change');
};

Select.prototype.deSelect = function(index) {
Select.prototype.deSelect = function(value) {
var selected = utils.getClassname('selected'),
selectionText = utils.getClassname('selectionText'),
selectionTag = utils.getClassname('selectionTag');
selectionTag = utils.getClassname('selectionTag'),
option = $('[data-value="' + value + '"]').parent();

if(!this.$drop) {
this.prepareDrop();
} else {
this.$drop.find('[data-value="' + value + '"]').parent().removeClass(selected)
}

this.$el.find('option:eq(' + index + ')').prop('selected', false);
this.$drop.find('#' + utils.getClassname('option') + '-' + index).removeClass(selected);
this.$selection.find('.' + selectionTag + '-' + index).remove();
this.$el.find('[value="' + value + '"]').removeAttr('selected');
option.removeClass(selected);
this.$selection.find('[data-value="' + value + '"]').remove();
this.$el.val($.grep(this.$el.val(), function(val) {
return val !== value;
}));

if(this.multiple && this.options.displayType !== 'tags' && this.$el.val() !== null) {
this.$selection
.find('.' + selectionText)
.html(this.options.multipleInfoMessage + ' ' + this.$el.val().length + '/' + this.optionData.length);
}

if(this.$el.val() === null) {
if(this.multiple && this.options.displayType === 'tags' && this.$el.val().length < 1) {
this.$selection.find('.' + selectionText).text(this.multiplePlaceholder);
}

Expand All @@ -596,7 +609,7 @@
};

Select.prototype.removeTag = function($tag) {
this.deSelect($tag.data('index'));
this.deSelect($tag.data('value'));
this.setDropPosition();
};

Expand Down Expand Up @@ -722,7 +735,11 @@
this.multiplePlaceholder = this.$el.attr('placeholder') || this.options.placeholder || '';

if(this.getSelected().length > 0) {
data.selectionText = this.renderSelectionTags();
if(this.options.displayType === 'text') {
data.selectionText = this.options.multipleInfoMessage + ' ' + this.getSelected().length + '/' + this.optionData.length;
} else {
data.selectionText = this.renderSelectionTags();
}
}
else {
data.selectionText = this.multiplePlaceholder;
Expand Down Expand Up @@ -1142,7 +1159,7 @@
});

// version
ux.version = '3.5.6';
ux.version = '3.5.7';

// default settings
ux.settings = defaults;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uxrocket.select",
"version": "3.5.6",
"version": "3.5.7",
"description": "jQuery based Select box replacement function",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion uxrocket.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Select",
"registry": "uxrocket.select",
"version": "3.5.6",
"version": "3.5.7",
"paths": {
"lib": "lib/",
"dist": "dist/",
Expand Down
4 changes: 4 additions & 0 deletions version.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Versiyon 3.5.7
- FIX: Display-type text olması durumunda pre-selected verilerin tag şeklinde gözükmesi problemi giderildi.
- FIX: Display-type tag olması durumunda pre-selected verilerin çalışması düzenlendi.

## Versiyon 3.5.6
- DEĞİŞİKLİK: Component'in initialize olmadığı durumda update methodu warning basacak şekilde düzenlendi.

Expand Down

0 comments on commit 253167a

Please sign in to comment.