File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
tests/cases/libs/view/helpers Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -674,6 +674,7 @@ function input($fieldName, $options = array()) {
674
674
}
675
675
676
676
if (!isset ($ options ['type ' ])) {
677
+ $ magicType = true ;
677
678
$ options ['type ' ] = 'text ' ;
678
679
$ fieldDef = array ();
679
680
if (isset ($ options ['options ' ])) {
@@ -716,13 +717,19 @@ function input($fieldName, $options = array()) {
716
717
}
717
718
$ types = array ('checkbox ' , 'radio ' , 'select ' );
718
719
719
- if (!isset ($ options ['options ' ]) && in_array ($ options ['type ' ], $ types )) {
720
+ if (
721
+ (!isset ($ options ['options ' ]) && in_array ($ options ['type ' ], $ types )) ||
722
+ (isset ($ magicType ) && $ options ['type ' ] == 'text ' )
723
+ ) {
720
724
$ view =& ClassRegistry::getObject ('view ' );
721
725
$ varName = Inflector::variable (
722
726
Inflector::pluralize (preg_replace ('/_id$/ ' , '' , $ fieldKey ))
723
727
);
724
728
$ varOptions = $ view ->getVar ($ varName );
725
729
if (is_array ($ varOptions )) {
730
+ if ($ options ['type ' ] !== 'radio ' ) {
731
+ $ options ['type ' ] = 'select ' ;
732
+ }
726
733
$ options ['options ' ] = $ varOptions ;
727
734
}
728
735
}
Original file line number Diff line number Diff line change @@ -2061,6 +2061,21 @@ function testInputOverridingMagicSelectType() {
2061
2061
'/div '
2062
2062
);
2063
2063
$ this ->assertTags ($ result , $ expected );
2064
+
2065
+ //Check that magic types still work for plural/singular vars
2066
+ $ view =& ClassRegistry::getObject ('view ' );
2067
+ $ view ->viewVars ['types ' ] = array ('value ' => 'good ' , 'other ' => 'bad ' );
2068
+ $ result = $ this ->Form ->input ('Model.type ' );
2069
+ $ expected = array (
2070
+ 'div ' => array ('class ' => 'input select ' ),
2071
+ 'label ' => array ('for ' => 'ModelType ' ), 'Type ' , '/label ' ,
2072
+ 'select ' => array ('name ' => 'data[Model][type] ' , 'id ' => 'ModelType ' ),
2073
+ array ('option ' => array ('value ' => 'value ' )), 'good ' , '/option ' ,
2074
+ array ('option ' => array ('value ' => 'other ' )), 'bad ' , '/option ' ,
2075
+ '/select ' ,
2076
+ '/div '
2077
+ );
2078
+ $ this ->assertTags ($ result , $ expected );
2064
2079
}
2065
2080
2066
2081
/**
You can’t perform that action at this time.
0 commit comments