allow getValue
method to return value itself, not object, fix #259
This commit is contained in:
parent
8287173d26
commit
90868b5bc1
@ -3,6 +3,7 @@ X-editable changelog
|
||||
|
||||
Version 1.4.5 wip
|
||||
----------------------------
|
||||
[enh #259] allow `getValue` method to return value itself, not object (vitalets)
|
||||
[enh] add `destroy` method to inputs (vitalets)
|
||||
[enh #164] allow emptytext to be html (vitalets)
|
||||
[enh #78] allow html in editable content (vitalets)
|
||||
|
@ -507,25 +507,34 @@ Makes editable any HTML element on the page. Applied as jQuery method.
|
||||
/**
|
||||
Returns current values of editable elements.
|
||||
Note that it returns an **object** with name-value pairs, not a value itself. It allows to get data from several elements.
|
||||
If value of some editable is `null` or `undefined` it is excluded from result object.
|
||||
If value of some editable is `null` or `undefined` it is excluded from result object.
|
||||
When param `isSingle` is set to **true** - it is supposed you have single element and will return value of editable instead of object.
|
||||
|
||||
@method getValue()
|
||||
@param {bool} isSingle whether to return just value of single element
|
||||
@returns {Object} object of element names and values
|
||||
@example
|
||||
$('#username, #fullname').editable('getValue');
|
||||
// possible result:
|
||||
//result:
|
||||
{
|
||||
username: "superuser",
|
||||
fullname: "John"
|
||||
}
|
||||
//isSingle = true
|
||||
$('#username').editable('getValue', true);
|
||||
//result "superuser"
|
||||
**/
|
||||
case 'getValue':
|
||||
this.each(function () {
|
||||
var $this = $(this), data = $this.data(datakey);
|
||||
if (data && data.value !== undefined && data.value !== null) {
|
||||
result[data.options.name] = data.input.value2submit(data.value);
|
||||
}
|
||||
});
|
||||
if(arguments.length === 2 && arguments[1] === true) { //isSingle = true
|
||||
result = this.eq(0).data(datakey).value;
|
||||
} else {
|
||||
this.each(function () {
|
||||
var $this = $(this), data = $this.data(datakey);
|
||||
if (data && data.value !== undefined && data.value !== null) {
|
||||
result[data.options.name] = data.input.value2submit(data.value);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
|
||||
/**
|
||||
|
@ -66,7 +66,19 @@ $(function () {
|
||||
equal(values.comment, '', 'textarea empty value') ;
|
||||
ok(!('sex' in values), 'select value not present') ;
|
||||
ok(!('dob' in values), 'date value not present') ;
|
||||
});
|
||||
});
|
||||
|
||||
test("getValue with isSingle = true", function () {
|
||||
var v = '123',
|
||||
e = $(
|
||||
'<a href="#" data-type="text" id="username">'+v+'</a>' +
|
||||
'<a href="#" data-type="textarea" id="comment">456</a>'
|
||||
).appendTo('#qunit-fixture').editable();
|
||||
|
||||
//check get value
|
||||
var value = e.editable('getValue', true);
|
||||
equal(value, v, 'value ok');
|
||||
});
|
||||
|
||||
test("'init' event", function () {
|
||||
expect(1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user