Opened 10 years ago

Closed 10 years ago

Last modified 5 years ago

#5246 closed bug (fixed)

_determineButtonType does not work if a label for checkbox/radiobutton is not yet attached to the document

Reported by: tomas Owned by: rdworth
Priority: blocker Milestone: 1.8
Component: ui.button Version: 1.8rc3
Keywords: Cc: thomas.nt@…
Blocked by: Blocking:

Description

Steps to reproduce:

$("body").appendItems(
  $('<div>')
    .append('<input type="checkbox" id="id1"><label for="id1">button1</label>')
    .buttonset()
);

This bug prevents simple building of complex DOM structures with buttons.

My suggestion is to replace the following line:

this.buttonElement = $( "[for=" + this.element.attr("id") + "]" );

with:

var selector = "[for=" + this.element.attr("id") + "]";
this.buttonElement = $( selector );
if (this.buttonElement.size() == 0)
  this.buttonElement = this.element.parent().last().find( selector );

Or some more efficient alternative:)

Change History (8)

comment:1 Changed 10 years ago by Scott González

The suggested fix isn't valid as it will only work in situations where the label happens to be the last element.

comment:2 Changed 10 years ago by tomas

I am not sure whether I understand properly, but it works even if the label is not the last element:

$("body").appendItems(
  $('<div>')
    .append('<label for="id1">button1</label><input type="checkbox" id="id1">')
    .buttonset()
);

comment:3 Changed 10 years ago by rdworth

Milestone: TBD1.8
Priority: minorblocker
Version: 1.8rc21.8rc3

comment:4 Changed 10 years ago by rdworth

Owner: set to rdworth
Status: newassigned

comment:5 Changed 10 years ago by Scott González

Sorry, I saw the .parent() and misunderstood. I now realize you meant .parents() and I understand the logic you're using.

comment:6 Changed 10 years ago by Scott González

Resolution: fixed
Status: assignedclosed

Fixed in r3883.

comment:7 Changed 10 years ago by tomas

I see, sorry for typo.

comment:8 Changed 5 years ago by chillaranand

same problem occurs if input is inside label http://fiddle.jshell.net/t2jhL9ru/5/

Note: See TracTickets for help on using tickets.