change source of select, fixes

This commit is contained in:
vitalets 2013-01-08 14:23:38 +04:00
parent f06b5c4d01
commit 939e0dba51
6 changed files with 65 additions and 3 deletions

@ -4,6 +4,7 @@ X-editable changelog
Version 1.4.0 wip
----------------------------
[enh] select: chnage source via option method, see #61 (vitalets)
[bug] select: source loaded twice if sourceCache = false (vitalets)
[enh] added `destroy` method, see #61 (vitalets)
[enh] textarea: added `rows` property (vitalets)

@ -311,6 +311,10 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
if(key === 'value') {
this.setValue(value);
}
//pass to input
if(this.input.option) {
this.input.option(key, value);
}
},
setValue: function(value, convertStr) {

@ -199,6 +199,11 @@ Makes editable any HTML element on the page. Applied as jQuery method.
//transfer new option to container!
if(this.container) {
this.container.option(key, value);
} else {
//pass option to input directly
if(this.input.option) {
this.input.option(key, value);
}
}
},

@ -151,11 +151,16 @@ To create your own input you can inherit from this class.
this.$input.addClass(this.options.inputclass);
}
},
setAttr: function(attr) {
if (this.options[attr]) {
this.$input.attr(attr, this.options[attr]);
}
}
},
option: function(key, value) {
this.options[key] = value;
}
};

@ -234,7 +234,17 @@ List - abstract class for inputs that have source option loaded from js array or
});
}
return result;
}
},
option: function(key, value) {
this.options[key] = value;
if(key === 'source') {
this.sourceData = null;
}
if(key === 'prepend') {
this.prependData = null;
}
}
});

@ -647,6 +647,43 @@ $(function () {
});
asyncTest("change source", function () {
var e = $('<a href="#" data-type="select" data-name="load-srv" data-value="2" data-source="groups.php"></a>').appendTo(fx).editable({
//need to disable cache to force request
sourceCache: false
});
setTimeout(function() {
e.click();
var p = tip(e);
equal(p.find('select').find('option').length, size, 'options loaded');
equal(p.find('select').val(), e.data('editable').value, 'selected value correct') ;
p.find('.editable-cancel').click();
ok(!p.is(':visible'), 'popover was closed');
$.mockjax({
url: 'groups1.php',
responseText: {a: 1, 2: 2}
});
//set new source
e.editable('option', 'source', 'groups1.php');
e.click();
setTimeout(function() {
ok(p.find('select').length, 'select exists');
equal(p.find('select').find('option').length, 2, 'new options loaded');
equal(p.find('select').val(), e.data('editable').value, 'selected value correct') ;
p.find('.editable-cancel').click();
ok(!p.is(':visible'), 'popover was closed');
e.remove();
start();
}, timeout);
}, timeout);
});
});