Merge pull request #5845 from cakephp/issue-5832

Don't create invalid maxlength attributes for decimal columns.
This commit is contained in:
Mark Story 2015-02-06 19:46:24 -05:00
commit 77e8110a1a
2 changed files with 27 additions and 1 deletions

View file

@ -763,6 +763,32 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
}
/**
* Tests correct generation of decimal fields as text inputs
*
* @return void
*/
public function testTextFieldGenerationForDecimalAsText() {
$this->Form->create('ValidateUser');
$result = $this->Form->input('cost_decimal', array(
'type' => 'text'
));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ValidateUserCostDecimal'),
'Cost Decimal',
'/label',
array('input' => array(
'type' => 'text',
'name' => 'data[ValidateUser][cost_decimal]',
'id' => 'ValidateUserCostDecimal',
'maxlength' => 6,
)),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Tests correct generation of number fields for integer fields
*

View file

@ -1292,7 +1292,7 @@ class FormHelper extends AppHelper {
if ($autoLength &&
in_array($options['type'], array('text', 'textarea', 'email', 'tel', 'url', 'search'))
) {
$options['maxlength'] = $fieldDef['length'];
$options['maxlength'] = (int)$fieldDef['length'];
}
return $options;
}