Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

Separating / removing label from checkbox or radiobutton #71

Closed
webdevilopers opened this issue Apr 25, 2014 · 7 comments
Closed

Separating / removing label from checkbox or radiobutton #71

webdevilopers opened this issue Apr 25, 2014 · 7 comments

Comments

@webdevilopers
Copy link
Contributor

For generating a checkbox my current view would look like this:

<tr>
  <td class='right-label'><?php echo $this->formLabel($contract->get('show_in_oem')); ?></td>
  <td><?php echo $this->formcheckbox($contract->get('show_in_oem')); ?></td>
</tr>

Which then would generate:

<tr>
  <td class="right-label"><label for="contract[show_in_oem]">Show in OEM</label></td>
  <td><input type="hidden" value="0" name="contract[show_in_oem]"><input type="checkbox" value="1" class="form-control" name="contract[show_in_oem]"></td>
</tr>

As you can see I have to separate the label from the checkbox.

Now, after switching to twb the same code generates this HTML:

<tr>
<td class="right-label">
<label for="contract[show_in_oem]">Show in OEM</label>
</td>
<td>
<div class="checkbox">
<input type="hidden" value="0" name="contract[show_in_oem]">
<label>
<input class="form-control" type="checkbox" value="1" name="contract[show_in_oem]">
Show in OEM
</label>
</div>
</td>
</tr>

When disabling TWB via elements' options this is the result:

<tr>
<td class="right-label">
<label for="contract[show_in_oem]">Show in OEM</label>
</td>
<td>
<input type="hidden" value="0" name="contract[show_in_oem]">
<label>
<input class="form-control" type="checkbox" value="1" name="contract[show_in_oem]">
Show in OEM
</label>
</td>
</tr>

Though I know that appending the label to the checkbox may be the expected Twitter Bootstrap 3 behaviour for horizontal forms maybe there are use cases where the label needs to be separated.

Is there an option to achieve this?

@webdevilopers webdevilopers changed the title Removable label for checkbox and radiobutton Separating / removing label from checkbox or radiobutton Apr 25, 2014
@webdevilopers
Copy link
Contributor Author

You may close thie request since it can be achieved by rendering the checkbox via forminput view helper instead of formcheckbox:

<tr>
  <td class='right-label'><?php echo $this->formLabel($contract->get('show_in_oem')); ?></td>
  <td><?php echo $this->forminput($contract->get('show_in_oem')); ?></td>
</tr>

@neilime neilime closed this as completed Apr 26, 2014
@webdevilopers
Copy link
Contributor Author

I am not sure how to re-open my issue.

My last workaround to get a checkbox without label was this:

<tr>
  <td class='right-label'><?php echo $this->formLabel($contract->get('show_in_oem')); ?></td>
  <td><?php echo $this->forminput($contract->get('show_in_oem')); ?></td>
</tr>

Unfortunately this prevents the checkbox value from being set f.e. when binding an object to the form that has a value set to '1'. My hydration is correct and when I switch back to the formcheckbox helper the value is set but the label appears.

@webdevilopers
Copy link
Contributor Author

Can you please check my latest post, @neilime and have look if this issue might be reopened? I see no option to do this myself.Thanks!

@neilime neilime reopened this May 12, 2014
@webdevilopers
Copy link
Contributor Author

I have seen your update on the code @neilime about the label position in issue #49 .
I will check if it fixes my issue too.

@neilime neilime closed this as completed May 13, 2014
@webdevilopers
Copy link
Contributor Author

Unfortunately the label position improvement #49 does not solve my problem, @neilime .

Should it be possible to use zf2-twb-bundle to generate form elements hiding / not including a label like in my featured case?

@neilime neilime reopened this May 14, 2014
@neilime
Copy link
Owner

neilime commented May 14, 2014

With the last version, you can set the disable-twb option to your checkbox element. Check out the readme.

@webdevilopers
Copy link
Contributor Author

Great and quick fix, @neilime . Thank you very much.

For anybody interested this is the view script code to have the label separated from the checkbox by table rows:

<tr>
    <td class='right-label'><?php echo $this->formLabel($contract->get('isWaresfilter')); ?></td>
    <td><?php echo $this->formcheckbox($contract->get('isWaresfilter')); ?></td>
</tr>

The cool thing is that the label can still be identified by the formLabel view helper allthough disable-twb was set.

Closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants