← Writing
K2 / Nintex 1 min read

Custom Controls in K2: Field Notes

Hard-won notes on building K2 custom controls that behave, from data binding to the runtime quirks nobody documents.

Custom controls are where K2 stops being a configuration exercise and starts being real software. They are also where the documentation thins out. These are the notes I wish I had on day one.

Bind late, render early

Read your bound value as late as you can, and paint the control as early as you can. K2 sets values through the control lifecycle, not all at once, so reading too eagerly gives you stale or empty data.

SourceCode.Forms.Controls.MyControl = function () {
this.init = function () {
// paint the shell now, fill it when the value arrives
this.render();
};
this.setValue = function (value) {
this.current = value;
this.refresh();
};
};

Respect the form theme

A control that ignores the host theme looks bolted on. Inherit colours and fonts from the form rather than hard coding them, and your control will pass for native.

Test on the slowest runtime you support

Desktop Chrome hides a lot of sins. The control that feels instant on your machine can stutter inside an embedded browser on a tired laptop. Test there before you ship, not after a user files the bug.