docs/docs/en/runjs/context/set-value.md
In JSField, JSItem, and other editable field contexts, sets the current field’s value. Use with ctx.getValue() for two-way binding with the form.
| Scenario | Description |
|---|---|
| JSField | Write user selection or computed value in editable custom fields |
| JSItem | Update current cell value in table/sub-table editable items |
| JSColumn | Update row field value when rendering a column |
Note:
ctx.setValue(v)is only available in RunJS contexts with form binding; in event flow, linkage, JSBlock, etc. (no field binding) the method may not exist—use optional chaining:ctx.setValue?.(value).
setValue<T = any>(value: T): void;
value is the value to write; type depends on the field’s form item type.ctx.setValue(v) updates the current field’s value in the Ant Design Form and triggers linkage and validation.ctx.getValue() to confirm.const { Input } = ctx.libs.antd;
const defaultValue = ctx.getValue() ?? '';
ctx.render(
<Input
defaultValue={defaultValue}
onChange={(e) => ctx.setValue(e.target.value)}
/>
);
const status = ctx.getValue();
if (status == null || status === '') {
ctx.setValue?.('draft');
}
const otherValue = ctx.form?.getFieldValue('type');
if (otherValue === 'custom') {
ctx.setValue?.({ label: 'Custom', value: 'custom' });
}
ctx.setValue may be undefined; use ctx.setValue?.(value).{ id, [titleField]: label }); see field config.js-field:value-change: container event when value changes from outside; use to update display