Ox.Filter: fix value reset on clicking (+) or (-), fix default value for item type

This commit is contained in:
rolux 2014-05-19 01:22:41 +02:00
parent c593955e8c
commit 17120e6aec

View file

@ -337,7 +337,9 @@ Ox.Filter = function(options, self) {
['string', 'text'].indexOf(oldConditionType) == -1 ['string', 'text'].indexOf(oldConditionType) == -1
|| ['string', 'text'].indexOf(newConditionType) == -1 || ['string', 'text'].indexOf(newConditionType) == -1
) { ) {
condition.value = self.defaultValue[newFindKey.type]; condition.value = newFindKey.type == 'item'
? newFindKey.values[0].id
: self.defaultValue[newFindKey.type];
} }
renderConditions(); renderConditions();
} }
@ -456,24 +458,28 @@ Ox.Filter = function(options, self) {
.css({margin: '0 4px 0 ' + (isGroup ? '292px' : '8px')}) // fixme: 296 is probably correct, but labels seem to be too wide .css({margin: '0 4px 0 ' + (isGroup ? '292px' : '8px')}) // fixme: 296 is probably correct, but labels seem to be too wide
.bindEvent({ .bindEvent({
click: function(data) { click: function(data) {
var key; var key, that = this;
if (self.options.value.conditions.length == 1) { that.$element.focus(); // make input trigger change
key = self.options.findKeys[0]; setTimeout(function() {
self.options.value.conditions = [{ Ox.print(self.options.value.conditions.length, that.$element.parent().data('subposition') == -1);
key: key.id, if (self.options.value.conditions.length == 1) {
value: '', key = self.options.findKeys[0];
operator: self.conditionOperators[key.type][0].id self.options.value.conditions = [{
}]; key: key.id,
renderConditions(); value: '',
triggerChangeEvent(); operator: self.conditionOperators[key.type][0].id
} else if (this.$element.parent().data('subposition') == -1) { }];
removeCondition(this.$element.parent().data('position')); renderConditions();
} else { triggerChangeEvent();
removeCondition( } else if (that.$element.parent().data('subposition') == -1) {
this.$element.parent().data('position'), removeCondition(that.$element.parent().data('position'));
this.$element.parent().data('subposition') } else {
); removeCondition(
} that.$element.parent().data('position'),
that.$element.parent().data('subposition')
);
}
});
} }
}), }),
Ox.Button({ Ox.Button({
@ -486,10 +492,8 @@ Ox.Filter = function(options, self) {
.bindEvent({ .bindEvent({
click: function(data) { click: function(data) {
var that = this; var that = this;
// timeout needed so that input change registers that.$element.focus(); // make input trigger change
// before all conditions are re-rendered
setTimeout(function() { setTimeout(function() {
Ox.Log('Form', 'add...', data, that.$element.parent().data('position'), that.$element.parent().data('subposition'))
if (that.$element.parent().data('subposition') == -1) { if (that.$element.parent().data('subposition') == -1) {
addCondition(that.$element.parent().data('position') + 1); addCondition(that.$element.parent().data('position') + 1);
} else { } else {
@ -512,8 +516,9 @@ Ox.Filter = function(options, self) {
.bindEvent({ .bindEvent({
click: function(data) { click: function(data) {
var that = this; var that = this;
that.$element.focus(); // make input trigger change
setTimeout(function() { setTimeout(function() {
addCondition(that.$element.parent().data('position') + 1, -1, true) addCondition(that.$element.parent().data('position') + 1, -1, true);
}); });
} }
}) })
@ -684,6 +689,8 @@ Ox.Filter = function(options, self) {
if (type == 'boolean') { if (type == 'boolean') {
$input = Ox.Select({ $input = Ox.Select({
items: ['true', 'false'], items: ['true', 'false'],
max: 1,
min: 1,
value: value ? 'true' : 'false', value: value ? 'true' : 'false',
width: 288 width: 288
}); });
@ -699,6 +706,8 @@ Ox.Filter = function(options, self) {
} else if (type == 'item') { } else if (type == 'item') {
$input = Ox.Select({ $input = Ox.Select({
items: findKey.values, items: findKey.values,
max: 1,
min: 1,
value: value, value: value,
width: 288 width: 288
}); });