Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow the formHelper->label() to have default options from inputDefaults #596

Closed
wants to merge 1 commit into from

3 participants

@nshahzad

This allows any labels to have their default options set using the inputDefaults() array.

I looked at the unit-tests for the formHelper, and I wasn't quite sure how to implement the tests, I can amend this commit with any tests, just advise me on the proper way to lay them out.

@nshahzad nshahzad allow the label to pick up default properties from the inputDefaults.…
… merges in any options and they can be overridden locally
c659084
@nshahzad nshahzad closed this
@ceeram
Collaborator

inputDefaults is only meant to be used with FormHelper input() method, not sure if other methods should use this as well.
If we would make other methods to use inputDefaults, we should do them all imo.
Pull requests targeted against master are not accepted, bugfix requests can be made for 2.1 branch, backwards compatible new features for 2.2

@nshahzad
@josegonzalez
Collaborator

@nshahzad perhaps labelDefaults?

@nshahzad

I fixed my pull-request to branch 2.2 and it's pull request #598

@nshahzad

labelDefaults would work better, yes, it's more accurate.

@ceeram
Collaborator

Why not use inputDefaults and Form->input()? you can set default label options in inputDefaults as well

@nshahzad

You can't, there are no options for 'label' under inputDefaults, and they're not merged into any options that are passed into label. input() does pass the options in, but that request a lot of repeated code for any labels that all have the same options; you have to add it to every input() call.

This is what my PR #598 does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 5, 2012
  1. @nshahzad

    allow the label to pick up default properties from the inputDefaults.…

    nshahzad authored
    … merges in any options and they can be overridden locally
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 0 deletions.
  1. +10 −0 lib/Cake/View/Helper/FormHelper.php
View
10 lib/Cake/View/Helper/FormHelper.php
@@ -795,6 +795,16 @@ public function label($fieldName = null, $text = null, $options = array()) {
$options = array('class' => $options);
}
+ if(!isset($options['class'])) {
+ if(isset($this->_inputDefaults['label'])) {
+ if(is_string($this->_inputDefaults['label'])) {
+ $options['class'] = $this->_inputDefaults['label'];
+ } else {
+ $options = array_merge($this->_inputDefaults['label'], $options);
+ }
+ }
+ }
+
if (isset($options['for'])) {
$labelFor = $options['for'];
unset($options['for']);
Something went wrong with that request. Please try again.