From: Coleman Watts Date: Mon, 21 Dec 2015 14:26:17 +0000 (-0500) Subject: Add support for number fields to CRM_Core_Form X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=092cb9c58c57e5ea467410117ee71a32b8d4c878;p=civicrm-core.git Add support for number fields to CRM_Core_Form --- diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index 9c0e424ad5..bdfcec58d5 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -111,7 +111,7 @@ class CRM_Contact_Form_Search_Criteria { $form->addElement('text', 'job_title', ts('Job Title'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'job_title')); //added internal ID - $form->addElement('text', 'contact_id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id')); + $form->add('number', 'contact_id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id') + array('min' => 1)); $form->addRule('contact_id', ts('Please enter valid Contact ID'), 'positiveInteger'); //added external ID diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 96393a5a8c..685f09d95a 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -326,10 +326,11 @@ class CRM_Core_Form extends HTML_QuickForm_Page { $type, $name, $label = '', $attributes = '', $required = FALSE, $extra = NULL ) { - if ($type == 'wysiwyg') { + // Fudge some extra types that quickform doesn't support + if ($type == 'wysiwyg' || $type == 'number') { $attributes = ($attributes ? $attributes : array()) + array('class' => ''); - $attributes['class'] .= ' crm-form-wysiwyg'; - $type = "textarea"; + $attributes['class'] = ltrim($attributes['class'] . " crm-form-$type"); + $type = $type == 'wysiwyg' ? 'textarea' : 'text'; } // @see http://wiki.civicrm.org/confluence/display/CRMDOC/crmDatepicker if ($type == 'datepicker') { diff --git a/CRM/Core/Form/Renderer.php b/CRM/Core/Form/Renderer.php index 1339757e57..86a39b8b47 100644 --- a/CRM/Core/Form/Renderer.php +++ b/CRM/Core/Form/Renderer.php @@ -192,6 +192,10 @@ class CRM_Core_Form_Renderer extends HTML_QuickForm_Renderer_ArraySmarty { 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'); + } if ($required) { $class .= ' required';