*/
private $_chainSelectFields = array();
+ /**
+ * Extra input types we support via the "add" method
+ * @var array
+ */
+ public static $html5Types = array(
+ 'number',
+ 'url',
+ 'email',
+ );
+
/**
* Constructor for the basic form page.
*
$attributes = '', $required = FALSE, $extra = NULL
) {
// Fudge some extra types that quickform doesn't support
- if ($type == 'wysiwyg' || $type == 'number') {
+ if ($type == 'wysiwyg' || in_array($type, self::$html5Types)) {
$attributes = ($attributes ? $attributes : array()) + array('class' => '');
$attributes['class'] = ltrim($attributes['class'] . " crm-form-$type");
$type = $type == 'wysiwyg' ? 'textarea' : 'text';
$isSelect = (in_array($widget, array(
'Select',
'Multi-Select',
- 'Select State/Province',
- 'Multi-Select State/Province',
- 'Select Country',
- 'Multi-Select Country',
'AdvMulti-Select',
'CheckBoxGroup',
'RadioGroup',
$props['data-api-field'] = $props['name'];
}
}
- //Use select2 library for following widgets.
- $isSelect2 = (in_array($widget, array(
- 'Select',
- 'Multi-Select',
- 'Select State/Province',
- 'Multi-Select State/Province',
- 'Select Country',
- 'Multi-Select Country',
- )));
- if ($isSelect2) {
+ // Use select2 library for following widgets.
+ if (in_array($widget, array('Select', 'Multi-Select'))) {
$props['class'] = (!empty($props['class']) ? $props['class'] . ' ' : '') . "crm-select2";
if ($props['context'] == 'search' || strpos($widget, 'Multi') !== FALSE) {
$props['class'] .= ' huge';
// TODO: refactor switch statement, to separate methods.
switch ($widget) {
case 'Text':
- case 'Link':
+ case 'Url':
+ case 'Number':
+ case 'Email':
//TODO: Autodetect ranges
$props['size'] = isset($props['size']) ? $props['size'] : 60;
- return $this->add('text', $name, $label, $props, $required);
+ return $this->add(strtolower($widget), $name, $label, $props, $required);
case 'hidden':
return $this->add('hidden', $name, NULL, $props, $required);
elseif (strpos($class, 'crm-form-contact-reference') !== FALSE) {
self::preprocessContactReference($element);
}
- // Hack to support number fields
- elseif (strpos($class, 'crm-form-number') !== FALSE) {
- $element->setAttribute('type', 'number');
+ // Hack to support html5 fields (number, url, etc)
+ else {
+ foreach (CRM_Core_Form::$html5Types as $type) {
+ if (strpos($class, "crm-form-$type") !== FALSE) {
+ $element->setAttribute('type', $type);
+ // Also add the "base" class for consistent styling
+ $class .= ' crm-form-text';
+ break;
+ }
+ }
}
if ($required) {