add defaultValue
option, related to #243
This commit is contained in:
parent
0471b7b01b
commit
241a217ab9
@ -3,6 +3,7 @@ X-editable changelog
|
||||
|
||||
Version 1.4.6 wip
|
||||
----------------------------
|
||||
[enh] add `defaultValue` option (vitalets)
|
||||
[enh #313] add composer support (masim)
|
||||
[enh #300] Fix 'bootstrap popover falls off page if editable is too close to window edge' (belerweb)
|
||||
[enh #302] allow data-datepicker and data-datetimepicker (vitalets)
|
||||
|
@ -102,7 +102,8 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
|
||||
this.error(false);
|
||||
this.input.$input.removeAttr('disabled');
|
||||
this.$form.find('.editable-submit').removeAttr('disabled');
|
||||
this.input.value2input(this.value);
|
||||
var value = (this.value === null || this.value === undefined || this.value === '') ? this.options.defaultValue : this.value;
|
||||
this.input.value2input(value);
|
||||
//attach submit handler
|
||||
this.$form.submit($.proxy(this.submit, this));
|
||||
}
|
||||
@ -477,6 +478,14 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
|
||||
**/
|
||||
value: null,
|
||||
/**
|
||||
Value that will be displayed in input if original field value is `null`.
|
||||
|
||||
@property defaultValue
|
||||
@type string|object
|
||||
@default null
|
||||
**/
|
||||
defaultValue: null,
|
||||
/**
|
||||
Strategy for sending data on server. Can be `auto|always|never`.
|
||||
When 'auto' data will be sent on server **only if pk and url defined**, otherwise new value will be stored locally.
|
||||
|
||||
|
@ -778,6 +778,18 @@ $(function () {
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
});
|
||||
|
||||
test("defaultValue", function () {
|
||||
var e = $('<a href="#" data-type="select"></a>').appendTo('#qunit-fixture').editable({
|
||||
source: groups,
|
||||
defaultValue: 3
|
||||
});
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
ok(p.find('select').length, 'select exists')
|
||||
equal(p.find('select').val(), 3, 'selected value correct');
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -547,6 +547,37 @@ $(function () {
|
||||
e.click();
|
||||
ok(!c.is(':visible'), 'clear hidden for empty input');
|
||||
});
|
||||
|
||||
test("defaultValue", function () {
|
||||
var e = $('<a href="#" data-name="text1"></a>').appendTo('#qunit-fixture').editable({
|
||||
defaultValue: '123'
|
||||
}),
|
||||
e1 = $('<a href="#" data-name="text1"></a>').appendTo('#qunit-fixture').editable({
|
||||
value: null,
|
||||
defaultValue: '123'
|
||||
});
|
||||
e2 = $('<a href="#" data-name="text1">qwe</a>').appendTo('#qunit-fixture').editable({
|
||||
defaultValue: '123'
|
||||
});
|
||||
|
||||
//empty text
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.find('input').length, 'input exists');
|
||||
equal(p.find('input').val(), '123', 'default text ok');
|
||||
|
||||
//empty value from js
|
||||
e1.click()
|
||||
p = tip(e1);
|
||||
ok(p.find('input').length, 'input exists');
|
||||
equal(p.find('input').val(), '123', 'default text ok');
|
||||
|
||||
//not empty
|
||||
e2.click()
|
||||
p = tip(e2);
|
||||
ok(p.find('input').length, 'input exists');
|
||||
equal(p.find('input').val(), 'qwe', 'default text not set as element not empty');
|
||||
});
|
||||
|
||||
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user