Search code examples
typescriptdojo2

Dojo2 How to force dojo 2 widget to re-render?


I am using dojo2 widget. I want to render the widget(VDOM) on form submit.

public submitFrom(input: any): void {
    console.log("want to re-render widget after this.");
}

In submitFrom I want re-render my dom.


Solution

  • I got the solution.

    Dojo 2 widgetbase has invalidate method, which force the widget to re-render. Dojo 2 Widgets can invoke invalidate() directly, however a non-widget can only emit an event with: this.emit({ type: 'invalidate' })

    public submitFrom(input: any): void {
      console.log("want to re-render widget after this.");
      // force the widget to re-render
      this.invalidate();
    }
    

    For non-widget need to do as follows:-

    public submitForm(): void {
        this.emit({ type: 'invalidate' });
    }