Ticket #340 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

Retrieve kauri-roles from html template

Reported by: idbr Owned by: freya
Priority: minor Milestone: 0.4
Component: modules/kauri-forms Version:
Keywords: Cc: kauri-discuss@…

Description

When creating complex controls (i.e. with mutiple html elements and specific layout), I find it easy to put a large blob of html in the control template, defining the whole control ,e.g.

$.extend(ListCreationControl.prototype.templates, {
  control : 
    "<table>" +
    "  <tr>" +
    "    <td><select kauri-role='selected' size='5' multiple='multiple'/></td>" +
    "    <td style='vertical-align: top;'><button kauri-role='remove'>Verwijderen</button></td>" +
    "  </tr>" +
    "  <tr>" +
    "    <td><input kauri-role='input' type='text' style='width:99%;'/></td>" +
    "    <td><button kauri-role='add'>Toevoegen</button></td>" +
    "  </tr>" +
    "</table>"
});

At run-time, the html element with kauri-role='control' is replaced with this blob, but it seems the kauri-role-elements from the template aren't indexed in the _elements registry. So, in the initContainerElements function, I've put:

var me = this;
var $listCreationControl = this.getElement();
$listCreationControl.find('[kauri-role]').each(function () {
  me.setElement($(this).attr('kauri-role'), $(this));
});

Maybe this could be done by default after inserting the template, or would that result in conflicts I'm not aware of?

Change History

comment:1 follow-up: ↓ 2 Changed 3 years ago by mpo

To make sure this also includes 'layout' indexing and other side effects it probably is wiser to delegate to the built-in indexing function.

Remaining question then is if the framework should trigger that automatically after applying the template. (imho it should like your use case suggests)

comment:2 in reply to: ↑ 1 Changed 3 years ago by freya

Hm the indexing of the inserted template should happen. Needs some debugging. The magic is happening in the _initElements method of control. (lookup method looks up elements in the element index and uses setElement to set it on the control)

ControlElements.index($element, this.getForm(), ( this.getParent() != undefined ) ? this.getParent().getAbsoluteId() : '/');

Replying to mpo:

To make sure this also includes 'layout' indexing and other side effects it probably is wiser to delegate to the built-in indexing function.

Remaining question then is if the framework should trigger that automatically after applying the template. (imho it should like your use case suggests)

comment:3 Changed 3 years ago by idbr

It seems that _initElements via ControlElements.index indeed indexes the template (kauri-index attributes are added to all elements in the template instance), but the ControlElements.lookup method isn't called for the different kauri-roles that are encounterd (nor another method that does control.setElement), so no roles are linked to elements in the registry.

comment:4 Changed 3 years ago by mpo

Haven't looked into code, but this sounds like

  • lookup isn't used
  • as a consequence the local copy of the form-index into the _elements member (ie a hashmap of roles local to the control) is not built up, and thus the getElement seek there fails

I'm guessing the lookup isn't really needed any more (since the adapted builder logic), and probably the local hashmap neither. Probably the easiest way out is to remove both and let the getElement() or control delegate to the ControlElements??

comment:5 Changed 3 years ago by freya

  • Owner changed from mpo to freya
  • Status changed from new to assigned

comment:6 Changed 3 years ago by freya

(In [1637]) see #340: lookup mechanism (used for sort of element cache in the control) just returns the element from elementIndex, as well as getElement does

comment:7 Changed 3 years ago by freya

ives, can you verify if your issue is covered by this last commit r1637

comment:8 Changed 3 years ago by idbr

  • Status changed from assigned to closed
  • Resolution set to fixed

Yes, this fixes it. Thanks

comment:9 Changed 3 years ago by jgou

  • Milestone changed from 0.4.1 to 0.4
Note: See TracTickets for help on using tickets.