Forum Stats

  • 3,733,825 Users
  • 2,246,827 Discussions


How to create Oj-Components dynamically?

User_INPR6 Member Posts: 6 Green Ribbon

Hey there,

so i want to create a Oj-Input-Text and my Code looks like this:

<oj-button on-oj-action="[[addinput]]">Add</oj-button>

var ojinput = document.createElement('oj-input-text');

  self.addinput = function() {

I dont get an error when running this, but but no element is displayed. What do I have to do to display an Oj input?

Thank you


Best Answer


  • Philip Sommer
    Philip Sommer Member Posts: 77 Red Ribbon

    Hi User_INPR6,

    I don't know about dynamlically instantiating oj-components. There may be issues with the knockout binding, because the newly inserted element is inserted into the DOM without a refresh of the bindings.

    But one reason may be you forgot to require ojs/ojinputtext. Check your define and require calls.

    A better way to do this in my opinion would be to add the oj-input outright and bind its' (or its' containers) display attribute to a knockout observable and switch that when pressing the button.



  • John 'JB' Brock-Oracle
    John 'JB' Brock-Oracle Posts: 2,546 Employee
    Accepted Answer

    This jsFiddle will show how it can be done.

    The oj-module with a dynamic config binding approach that Philip alluded to may be a better approach.

Sign In or Register to comment.