Skip to content

Commit

Permalink
changed behavior of cleanModel
Browse files Browse the repository at this point in the history
  • Loading branch information
o.istomin committed Sep 4, 2015
1 parent 8f47e01 commit ec3fd50
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 63 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## 0.2.12

#### Features

- **oi-select-options:**
- cleanModel: changed behavior (clean model by click)

#### Bug Fixes

- **oi-select-options:**
Expand Down
39 changes: 21 additions & 18 deletions dist/select-tpls.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,11 @@ angular.module('oi.select')
placeholderFn = $interpolate(attrs.placeholder || ''),
optionsFn = $parse(attrs.oiSelectOptions),
keyUpDownWerePressed = false,
matchesWereReset = false,
cleanModel = true;
matchesWereReset = false;

var timeoutPromise,
lastQuery;
lastQuery,
removedItem;

return function(scope, element, attrs, ctrl) {
var inputElement = element.find('input'),
Expand Down Expand Up @@ -414,6 +414,10 @@ angular.module('oi.select')
};
}

if (options.cleanModel) {
element.addClass('cleanMode');
}

var unbindFocusBlur = oiUtils.bindFocusBlur(element, inputElement);

if (angular.isDefined(attrs.autofocus)) {
Expand Down Expand Up @@ -553,15 +557,12 @@ angular.module('oi.select')
resetMatches({query: true});
}

cleanModel = false;
scope.oldQuery = scope.oldQuery || scope.query;
scope.query = '';
scope.backspaceFocus = false;
};

scope.removeItem = function removeItem(position) {
var removedItem;

if (attrs.disabled || !multiple && !scope.inputHide) return;

if (multiple && position >= 0) {
Expand All @@ -573,6 +574,10 @@ angular.module('oi.select')
if (!multiple) {
removedItem = ctrl.$modelValue;
cleanInput();

if (options.cleanModel) {
ctrl.$setViewValue(undefined);
}
}

if (!editItemCorrect && (multiple || !scope.backspaceFocus)) {
Expand Down Expand Up @@ -639,6 +644,10 @@ angular.module('oi.select')
case 27: /* esc */
if (!multiple) {
restoreInput();

if (options.cleanModel) {
ctrl.$setViewValue(removedItem);
}
}
resetMatches();
break;
Expand All @@ -665,16 +674,16 @@ angular.module('oi.select')
}
};

scope.getSearchLabel = function(option) {
var label = getLabel(option);
scope.getSearchLabel = function(item) {
var label = getLabel(item);

return searchFilter(label, scope.oldQuery || scope.query, option, searchFilterOptionsFn(scope.$parent));
return searchFilter(label, scope.oldQuery || scope.query, item, searchFilterOptionsFn(scope.$parent));
};

scope.getDropdownLabel = function(option) {
var label = getLabel(option);
scope.getDropdownLabel = function(item) {
var label = getLabel(item);

return dropdownFilter(label, scope.oldQuery || scope.query, option, dropdownFilterOptionsFn(scope.$parent));
return dropdownFilter(label, scope.oldQuery || scope.query, item, dropdownFilterOptionsFn(scope.$parent));
};

scope.getDisableWhen = getDisableWhen;
Expand Down Expand Up @@ -738,14 +747,9 @@ angular.module('oi.select')
scope.isFocused = false;

if (!multiple) {
if (options.cleanModel && !scope.inputHide) {
ctrl.$setViewValue(undefined);
}
restoreInput();
}

cleanModel = true;

saveOn('blur');
scope.$evalAsync();
}
Expand All @@ -767,7 +771,6 @@ angular.module('oi.select')
.then(function(data) {
if (isItemSave) {
scope.addItem(data);
cleanModel = true;
}
})
.finally(function() {
Expand Down
2 changes: 1 addition & 1 deletion dist/select-tpls.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/select.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ oi-select:not([multiple]) .select-search-list-item_selection {
border-color: #fff;
text-align: left;
}
oi-select:not([multiple]) .select-search-list-item_selection-remove {
display: none;
}
oi-select:not([multiple]) .select-search-list-item_selection:not(:active) {
background: none;
}
oi-select:not([multiple]) .select-search:after {
oi-select:not([multiple]):not(.cleanMode) .select-search-list-item_selection-remove {
display: none;
}
oi-select:not([multiple]):not(.cleanMode) .select-search:after {
content: "";
position: absolute;
display: block;
Expand Down
39 changes: 21 additions & 18 deletions dist/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,11 @@ angular.module('oi.select')
placeholderFn = $interpolate(attrs.placeholder || ''),
optionsFn = $parse(attrs.oiSelectOptions),
keyUpDownWerePressed = false,
matchesWereReset = false,
cleanModel = true;
matchesWereReset = false;

var timeoutPromise,
lastQuery;
lastQuery,
removedItem;

return function(scope, element, attrs, ctrl) {
var inputElement = element.find('input'),
Expand Down Expand Up @@ -414,6 +414,10 @@ angular.module('oi.select')
};
}

if (options.cleanModel) {
element.addClass('cleanMode');
}

var unbindFocusBlur = oiUtils.bindFocusBlur(element, inputElement);

if (angular.isDefined(attrs.autofocus)) {
Expand Down Expand Up @@ -553,15 +557,12 @@ angular.module('oi.select')
resetMatches({query: true});
}

cleanModel = false;
scope.oldQuery = scope.oldQuery || scope.query;
scope.query = '';
scope.backspaceFocus = false;
};

scope.removeItem = function removeItem(position) {
var removedItem;

if (attrs.disabled || !multiple && !scope.inputHide) return;

if (multiple && position >= 0) {
Expand All @@ -573,6 +574,10 @@ angular.module('oi.select')
if (!multiple) {
removedItem = ctrl.$modelValue;
cleanInput();

if (options.cleanModel) {
ctrl.$setViewValue(undefined);
}
}

if (!editItemCorrect && (multiple || !scope.backspaceFocus)) {
Expand Down Expand Up @@ -639,6 +644,10 @@ angular.module('oi.select')
case 27: /* esc */
if (!multiple) {
restoreInput();

if (options.cleanModel) {
ctrl.$setViewValue(removedItem);
}
}
resetMatches();
break;
Expand All @@ -665,16 +674,16 @@ angular.module('oi.select')
}
};

scope.getSearchLabel = function(option) {
var label = getLabel(option);
scope.getSearchLabel = function(item) {
var label = getLabel(item);

return searchFilter(label, scope.oldQuery || scope.query, option, searchFilterOptionsFn(scope.$parent));
return searchFilter(label, scope.oldQuery || scope.query, item, searchFilterOptionsFn(scope.$parent));
};

scope.getDropdownLabel = function(option) {
var label = getLabel(option);
scope.getDropdownLabel = function(item) {
var label = getLabel(item);

return dropdownFilter(label, scope.oldQuery || scope.query, option, dropdownFilterOptionsFn(scope.$parent));
return dropdownFilter(label, scope.oldQuery || scope.query, item, dropdownFilterOptionsFn(scope.$parent));
};

scope.getDisableWhen = getDisableWhen;
Expand Down Expand Up @@ -738,14 +747,9 @@ angular.module('oi.select')
scope.isFocused = false;

if (!multiple) {
if (options.cleanModel && !scope.inputHide) {
ctrl.$setViewValue(undefined);
}
restoreInput();
}

cleanModel = true;

saveOn('blur');
scope.$evalAsync();
}
Expand All @@ -767,7 +771,6 @@ angular.module('oi.select')
.then(function(data) {
if (isItemSave) {
scope.addItem(data);
cleanModel = true;
}
})
.finally(function() {
Expand Down
Loading

0 comments on commit ec3fd50

Please sign in to comment.