addBefore and enyo.UiComponent.addControl()

So, when using addBefore to insert components, UiComponent redorders UiComponent.children array, but leaves UiComponent.controls in a first added to last added order.

This causes getClientControls() to return the list of controls out of the order they appear.

I needed the list in order because i was styling the list of controls that needed to be in the order they were displayed on the screen.

I over rid enyo.UiComponent.addControl() in my kind to also reorder the control array.
addControl: function(inControl, inBefore) {
		// Called to add an already created control to the object's control list. It is
		// not used to create controls and should likely not be called directly.
		// It can be overridden to detect when controls are added.
		if (inBefore !== undefined) {
			var idx = (inBefore === null) ? 0 : this.indexOfChild(inBefore);
			this.controls.splice(idx, 0, inControl);
		} else {
			this.controls.push(inControl);
		}
		// When we add a Control, we also establish a parent.
		this.addChild(inControl, inBefore);
	},
Is there a reason controls is not modified as well as the children?

Comments

  • edited May 2013
    I think it was just an oversight when I coded this up. I just looked at your change and it makes sense to me. While it's possible for a control to be in the controls list and not the child list, that's handled in addChild, so this seems pretty safe. I'll do some more testing and check this in for 2.3.
  • All i did was copy and paste the code from addChild, and changed some variable names.

    I changed UiComponent in my local copy of enyo to use this function instead and I havn't seen any issues in my app.
Sign In or Register to comment.