我想在创建表单时用内容填充表单的textarea。我正在尝试使用onRender事件,但该字段未定义,因此其值为'财产无法改变。
在下面的代码片段中可以看到,“加载”按钮成功将内容插入到textarea中,但onRender事件无法执行此操作。
<input [(ngModel)]="nome" [ngModelOptions]="{standalone: true}" />
&#13;
$(function () {
$('#form').w2form({
name : 'form',
fields: [
{ field: 'comments', type: 'textarea'}
],
// Load some content inside text area onRender.
onRender: function(event) {
event.onComplete = function () {
// Option 1: Get from class.
//document.getElementsByClassName('foo')[0].value = "Fill text" // This does nothing.
// Option 2: Get from object.
if (this.fields[0].el != undefined) {
this.fields[0].el.value = "Fill text" // This raises error because this.fields[0].el does not exist yet.
}
}
},
actions: {
load: function () {
// Option 1: Get from class.
//document.getElementsByClassName('foo')[0].value = "Fill text"
// Option 2: Get from object.
this.fields[0].el.value = "Fill text"
}
}
});
});
&#13;
答案 0 :(得分:1)
您可以使用w2form.record
:
$(function () {
$('#form').w2form({
name : 'form',
fields: [
{ field: 'comments', type: 'textarea'}
],
record: {
"comments": "Hello World!"
}
});
});