Aura.Html
Aura.Html copied to clipboard
individual attributes for each option (multi checkbox)
Hi guys, today I needed to set some data-attributes for a particular input in a multi checkbox, are you interested in this feature? :)
@rodsouto isn't it the same one you send https://github.com/auraphp/Aura.Html/pull/46 ?
Sorry I understood it wrongly :) . Thanks for the PR.
Thanks @harikt :+1:
Hey @jakejohns ,
Do you think we are good to merge this ?
I like the concept. Here's some concerns off the top of my head:
Update Docs
README-FORMS.md
needs updating. In fact, I don't think the "multiple
" function is even documented there, unless i'm missing it.
Should this apply to other helpers?
I wonder if similar function should be applied to Radio
and Select
options. I think Radio
might be as easy as moving the prep
of this to AbstractChecked
and doing a similar thing to the multiple
method. I think Select
might be more difficult, and could wait if so
Spec Structure
I actually think the way it's being done here is probably the right option, but I just thought I'd throw this out there to explicitly rule it out for a valid reason. I haven't messed with the Checked
helpers too much, so I very well may be missing something here.
I sort of wish the attrs
weren't separate from the other content, requiring the keys to match in different arrays. But It's probably not a good idea to mess with the spec structure too much, right? eg. this is worse, or wouldn't work, right? Maybe not?:
<?php
// calling
$actual = $checkbox(array(
'name' => 'foo',
'value' => 'yes',
'options' => array(
'yes' => array(
'label' => 'Yes',
'attr' => array('class' => 'test-class')
),
'no' => array(
'label' => 'No',
'attr' => array('data-no' => 1)
),
)
));
// Checkbox.php ... totally untested
protected function multiple()
{
$html = '';
$checkbox = clone($this);
$this->attribs['name'] .= '[]';
foreach ($this->options as $value => $label) {
$attr = array();
if (is_array($label)) {
$attr = $label['attr'];
$label = $label['label'];
}
$this->attribs['value'] = $value;
$this->attribs['label'] = $label;
$html .= $checkbox(array(
'name' => $this->attribs['name'],
'value' => $this->value,
'attribs' => $this->attribs + $attr
));
}
return $html;
}