Permalink
Browse files

Added "tel" and "email" input type guessing.

Closes #3557
  • Loading branch information...
1 parent 4af6039 commit 422ceaff8516fc16c91a18ba735f5fe2039b6e02 @ADmad ADmad committed Jan 25, 2013
Showing with 24 additions and 18 deletions.
  1. +17 −17 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +7 −1 lib/Cake/View/Helper/FormHelper.php
@@ -1826,12 +1826,12 @@ public function testInput() {
$result = $this->Form->input('Contact.email', array('id' => 'custom'));
$expected = array(
- 'div' => array('class' => 'input text'),
+ 'div' => array('class' => 'input email'),
'label' => array('for' => 'custom'),
'Email',
'/label',
array('input' => array(
- 'type' => 'text', 'name' => 'data[Contact][email]',
+ 'type' => 'email', 'name' => 'data[Contact][email]',
'id' => 'custom', 'maxlength' => 255
)),
'/div'
@@ -1845,7 +1845,7 @@ public function testInput() {
'Email',
'/label',
array('input' => array(
- 'type' => 'text', 'name' => 'data[Contact][email]',
+ 'type' => 'email', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail', 'maxlength' => 255
)),
'/div'
@@ -1920,12 +1920,12 @@ public function testInput() {
$this->Form->request->data = array('Contact' => array('phone' => 'Hello & World > weird chars'));
$result = $this->Form->input('Contact.phone');
$expected = array(
- 'div' => array('class' => 'input text'),
+ 'div' => array('class' => 'input tel'),
'label' => array('for' => 'ContactPhone'),
'Phone',
'/label',
array('input' => array(
- 'type' => 'text', 'name' => 'data[Contact][phone]',
+ 'type' => 'tel', 'name' => 'data[Contact][phone]',
'value' => 'Hello & World > weird chars',
'id' => 'ContactPhone', 'maxlength' => 255
)),
@@ -2808,9 +2808,9 @@ public function testFormInputs() {
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
- array('div' => array('class' => 'input text')),
+ array('div' => array('class' => 'input email')),
'*/div',
- array('div' => array('class' => 'input text')),
+ array('div' => array('class' => 'input tel')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
@@ -2833,9 +2833,9 @@ public function testFormInputs() {
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
- array('div' => array('class' => 'input text')),
+ array('div' => array('class' => 'input email')),
'*/div',
- array('div' => array('class' => 'input text')),
+ array('div' => array('class' => 'input tel')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
@@ -2863,9 +2863,9 @@ public function testFormInputs() {
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
- array('div' => array('class' => 'input text')),
+ array('div' => array('class' => 'input email')),
'*/div',
- array('div' => array('class' => 'input text')),
+ array('div' => array('class' => 'input tel')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
@@ -2889,9 +2889,9 @@ public function testFormInputs() {
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
- array('div' => array('class' => 'input text')),
+ array('div' => array('class' => 'input email')),
'*/div',
- array('div' => array('class' => 'input text')),
+ array('div' => array('class' => 'input tel')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
@@ -2922,9 +2922,9 @@ public function testFormInputs() {
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
- array('div' => array('class' => 'input text')),
+ array('div' => array('class' => 'input email')),
'*/div',
- array('div' => array('class' => 'input text')),
+ array('div' => array('class' => 'input tel')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
@@ -2952,9 +2952,9 @@ public function testFormInputs() {
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
array('div' => array('class' => 'input text')),
'*/div',
- array('div' => array('class' => 'input text')),
+ array('div' => array('class' => 'input email')),
'*/div',
- array('div' => array('class' => 'input text')),
+ array('div' => array('class' => 'input tel')),
'*/div',
array('div' => array('class' => 'input password')),
'*/div',
@@ -1129,6 +1129,10 @@ protected function _magicOptions($options) {
$options['type'] = 'select';
} elseif (in_array($fieldKey, array('psword', 'passwd', 'password'))) {
$options['type'] = 'password';
+ } elseif (in_array($fieldKey, array('tel', 'telephone', 'phone'))) {
+ $options['type'] = 'tel';
+ } elseif ($fieldKey === 'email') {
+ $options['type'] = 'email';
} elseif (isset($options['checked'])) {
$options['type'] = 'checkbox';
} elseif ($fieldDef = $this->_introspectModel($modelKey, 'fields', $fieldKey)) {
@@ -1235,7 +1239,9 @@ protected function _maxLength($options) {
is_scalar($fieldDef['length']) &&
$options['type'] !== 'select'
);
- if ($autoLength && $options['type'] == 'text') {
+ if ($autoLength &&
+ in_array($options['type'], array('text', 'email', 'tel', 'url'))
+ ) {
$options['maxlength'] = $fieldDef['length'];
}
if ($autoLength && $fieldDef['type'] == 'float') {

0 comments on commit 422ceaf

Please sign in to comment.