From 27f6794a02f7cefb7a0ddac862826207cf65c40c Mon Sep 17 00:00:00 2001
From: Mariano D'Agostino <dagmar@154086.no-reply.drupal.org>
Date: Thu, 14 Jun 2012 21:51:27 -0300
Subject: [PATCH] Issue #1301746: Allow to trim extra spaces in exposed filters

---
 handlers/views_handler_filter.inc        |    4 ++++
 handlers/views_handler_filter_string.inc |   17 +++++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/handlers/views_handler_filter.inc b/handlers/views_handler_filter.inc
index b8c6ac1..29dd378 100644
--- a/handlers/views_handler_filter.inc
+++ b/handlers/views_handler_filter.inc
@@ -583,6 +583,10 @@ class views_handler_filter extends views_handler {
     if (!empty($this->options['expose']['identifier'])) {
       $value = $input[$this->options['expose']['identifier']];
 
+      if (!empty($this->options['expose']['trim_spaces']) && !is_array($value)) {
+        $value = trim($value);
+      }
+
       // Various ways to check for the absence of non-required input.
       if (empty($this->options['expose']['required'])) {
         if (($this->operator == 'empty' || $this->operator == 'not empty') && $value === '') {
diff --git a/handlers/views_handler_filter_string.inc b/handlers/views_handler_filter_string.inc
index a42cd69..68ad661 100644
--- a/handlers/views_handler_filter_string.inc
+++ b/handlers/views_handler_filter_string.inc
@@ -19,6 +19,7 @@ class views_handler_filter_string extends views_handler_filter {
     $options = parent::option_definition();
 
     $options['expose']['contains']['required'] = array('default' => FALSE, 'bool' => TRUE);
+    $options['expose']['contains']['trim_spaces'] = array('default' => FALSE, 'bool' => TRUE);
 
     return $options;
   }
@@ -175,6 +176,22 @@ class views_handler_filter_string extends views_handler_filter {
   }
 
   /**
+   * Options form subform for exposed filter options.
+   *
+   * @see options_form()
+   */
+  function expose_form(&$form, &$form_state) {
+    parent::expose_form($form, $form_state);
+
+    $form['expose']['trim_spaces'] = array(
+      '#type' => 'checkbox',
+      '#default_value' => $this->options['expose']['trim_spaces'],
+      '#title' => t('Trim initial and ending spaces'),
+      '#description' => t('If checked, blank spaces from the beginning and end of the input will be removed.'),
+    );
+  }
+
+  /**
    * Provide a simple textfield for equality
    */
   function value_form(&$form, &$form_state) {
-- 
1.7.1

