i'm a little confused about how labels & inputs are assigned for/id pairs 
in FormHelper.

Here's the code i have (it's inside a foreach of an entity collection):

$attrId = 'Listing.ItemAttr.' . $attr->id;
echo
  $this->Html->div('columns small-16 medium-8',
    $this->Form->label($attrId, // [for] attribute
      $this->Form->checkbox(
        $attrId, // [name] attribute
        [
           'id' => $attrId, // [id] attribute - if i skip this for checkbox 
inputs, i don't get an [id] attribute.
           // 'label' => $attr->name >> turns into <input type="checkbox" 
label="Attribute Name">
           // other checkbox attributes
        ]
      ) . $attr->name,
      [
         'escape' => FALSE
      ]
    ) // end label
);

The resulting HTML:

<div class="columns small-16 medium-8">
  <label for="listing-itemattr-3">
    <input type="checkbox" id="Listing.ItemAttr.3" name="
Listing[ItemAttr][3]">Attribute Name
  </label>
</div>

The label passes the [for] attribute through FormHelper::_domId, which i'd 
expect. But the [id] attribute doesn't appear to get the same treatment. i 
changed the checkbox() call to input() and the same ID string was assigned. 
It looks like an auto-generated ID is passed through _domId, but that only 
gets into the attributes if 'id' isn't already set in that array.

i also discovered that in the checkbox() method, a 'label' key is turned 
into an attribute of the input, not used to generate a wrapping <label> 
element as with most other inputs. Peculiar. So i'm doing this manual 
structure (which is fine, i also need to customize some other parts of the 
HTML anyway). 

*Question 1*: In FormHelper::input(), shouldn't the ID attribute be 
adjusted with _domId *after* the $options array is complete? Or is there an 
issue in checkbox() that it's not outputting the generated ID to HTML?

*Question 2*: Any suggestions how to get the wrapping label's [for] to 
match the checkbox's [id] until one of the above is addressed?

Thanks.
-joe t.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Reply via email to