1

We are using Search API for a customer website and we have a View with a start and end date exposed filter.

The view only filters correctly if we use the m/d/Y format, which is not valid in Brazil, as we use the d/m/Y format (with the day first).

I tried to search for solutions, but mostly use custom code or use Better Exposed Filters, which is not stable in Drupal 8. Date Popup also doesn't work with Search API fields. Although they fixed it, they didn't release a new version since 2017 (the fix is only available in the dev branch I guess).

I tried to create a new Date Format in "Date and Time Formats" and set the date field to this format, but that doesn't work too.

Using non-stable modules is not a choice and I would prefer to solve this using only Drupal UI (not any custom code)

View Settings View Settings

Tried to filter from 18/04/2020 to 22/04/2020, there's a content written in 20/04/2020, but nothing is returned Tried to filter from 18/04/2020 to 22/04/2020, there's a content written in 20/04/2020, but nothing is returned

PS: The screenshots are in Portuguese (Brazil), sorry for that.

Here's an export of the view, if that helps:

    uuid: e60ffc0d-fa69-4581-8ee5-585f128ffcec
    langcode: pt-br
    status: true
    dependencies:
      config:
        - field.storage.node.body
        - field.storage.node.field_tags
        - search_api.index.conteudo
        - taxonomy.vocabulary.tags
      module:
        - search_api
        - text
        - views_infinite_scroll
    id: busca
    label: Busca
    module: views
    description: ''
    tag: ''
    base_table: search_api_index_conteudo
    base_field: search_api_id
    display:
      default:
        display_plugin: default
        id: default
        display_title: Master
        position: 0
        display_options:
          access:
            type: none
            options: {  }
          cache:
            type: tag
            options: {  }
          query:
            type: views_query
            options:
              bypass_access: false
              skip_access: false
              preserve_facet_query_args: false
          exposed_form:
            type: input_required
            options:
              submit_button: Buscar
              reset_button: true
              reset_button_label: Limpar
              exposed_sorts_label: 'Ordenar por'
              expose_sort_order: true
              sort_asc_label: 'Ordem crescente'
              sort_desc_label: 'Ordem decrescente'
              text_input_required: 'Aplique um filtro para ver os resultados'
              text_input_required_format: raw_html
          pager:
            type: infinite_scroll
            options:
              items_per_page: 15
              offset: 0
              id: 0
              total_pages: null
              tags:
                previous: Anterior
                next: Próximo
              expose:
                items_per_page: false
                items_per_page_label: 'Items per page'
                items_per_page_options: '5, 10, 25, 50'
                items_per_page_options_all: false
                items_per_page_options_all_label: '- All -'
                offset: false
                offset_label: Offset
              views_infinite_scroll:
                button_text: 'Total de Resultados: @total | Carregar mais @next_page_count'
                automatically_load_content: false
          style:
            type: default
          row:
            type: fields
          fields:
            created:
              id: created
              table: search_api_datasource_conteudo_entity_node
              field: created
              relationship: none
              group_type: group
              admin_label: ''
              label: ''
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: created
              element_label_type: ''
              element_label_class: ''
              element_label_colon: false
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              click_sort_column: value
              type: timestamp
              settings:
                date_format: custom
                custom_date_format: d/m/Y
                timezone: ''
              group_column: value
              group_columns: {  }
              group_rows: true
              delta_limit: 0
              delta_offset: 0
              delta_reversed: false
              delta_first_last: false
              multi_type: separator
              separator: ', '
              field_api_classes: false
              field_rendering: true
              fallback_handler: search_api_date
              fallback_options:
                date_format: fallback
                custom_date_format: ''
                timezone: ''
                link_to_item: false
                use_highlighting: false
                multi_type: separator
                multi_separator: ', '
              entity_type: node
              plugin_id: search_api_field
            title:
              id: title
              table: search_api_index_conteudo
              field: title
              relationship: none
              group_type: group
              admin_label: ''
              label: ''
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: title
              element_label_type: ''
              element_label_class: ''
              element_label_colon: false
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              click_sort_column: value
              type: string
              settings:
                link_to_entity: true
              group_column: value
              group_columns: {  }
              group_rows: true
              delta_limit: 0
              delta_offset: 0
              delta_reversed: false
              delta_first_last: false
              multi_type: separator
              separator: ', '
              field_api_classes: false
              field_rendering: true
              fallback_handler: search_api
              fallback_options:
                link_to_item: false
                use_highlighting: false
                multi_type: separator
                multi_separator: ', '
              plugin_id: search_api_field
            body:
              id: body
              table: search_api_index_conteudo
              field: body
              relationship: none
              group_type: group
              admin_label: ''
              label: ''
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 250
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: true
                trim: true
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: body
              element_label_type: ''
              element_label_class: ''
              element_label_colon: false
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              click_sort_column: value
              type: text_default
              settings: {  }
              group_column: value
              group_columns: {  }
              group_rows: true
              delta_limit: 0
              delta_offset: 0
              delta_reversed: false
              delta_first_last: false
              multi_type: separator
              separator: ', '
              field_api_classes: false
              field_rendering: true
              fallback_handler: search_api
              fallback_options:
                link_to_item: false
                use_highlighting: false
                multi_type: separator
                multi_separator: ', '
              plugin_id: search_api_field
            field_tags:
              id: field_tags
              table: search_api_datasource_conteudo_entity_node
              field: field_tags
              relationship: none
              group_type: group
              admin_label: ''
              label: ''
              exclude: true
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: false
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: false
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              click_sort_column: target_id
              type: entity_reference_label
              settings:
                link: true
              group_column: target_id
              group_columns: {  }
              group_rows: true
              delta_limit: 0
              delta_offset: 0
              delta_reversed: false
              delta_first_last: false
              multi_type: separator
              separator: ', '
              field_api_classes: false
              field_rendering: true
              fallback_handler: search_api_entity
              fallback_options:
                link_to_item: false
                use_highlighting: false
                multi_type: separator
                multi_separator: ', '
                display_methods:
                  abrangencia_do_evento:
                    display_method: label
                  agendas:
                    display_method: label
                  albuns:
                    display_method: label
                    view_mode: default
                  autoria:
                    display_method: label
                  categoria_do_evento:
                    display_method: label
                  categorias_de_noticias:
                    display_method: label
                  categorias_do_banco_de_imagens:
                    display_method: label
                    view_mode: default
                  categorias_do_banco_de_videos:
                    display_method: label
                  grupo:
                    display_method: label
                  grupos:
                    display_method: label
                  grupos_de_links:
                    display_method: label
                  local_de_publicacao_do_evento:
                    display_method: label
                  representante_do_evento:
                    display_method: label
                  subdivisao_de_grupos:
                    display_method: label
                  tags:
                    display_method: label
                  tipo_do_evento:
                    display_method: label
              entity_type: node
              plugin_id: search_api_field
            created_1:
              id: created_1
              table: search_api_datasource_conteudo_entity_node
              field: created
              relationship: none
              group_type: group
              admin_label: ''
              label: ''
              exclude: true
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: false
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              click_sort_column: value
              type: timestamp
              settings:
                date_format: d_m_y
                custom_date_format: d/m/Y
                timezone: America/Sao_Paulo
              group_column: value
              group_columns: {  }
              group_rows: true
              delta_limit: 0
              delta_offset: 0
              delta_reversed: false
              delta_first_last: false
              multi_type: separator
              separator: ', '
              field_api_classes: false
              field_rendering: true
              fallback_handler: search_api_date
              fallback_options:
                date_format: fallback
                custom_date_format: ''
                timezone: ''
                link_to_item: false
                use_highlighting: false
                multi_type: separator
                multi_separator: ', '
              entity_type: node
              plugin_id: search_api_field
          filters:
            search_api_fulltext:
              id: search_api_fulltext
              table: search_api_index_conteudo
              field: search_api_fulltext
              relationship: none
              group_type: group
              admin_label: ''
              operator: and
              value: ''
              group: 1
              exposed: true
              expose:
                operator_id: search_api_fulltext_op
                label: 'Termo da Pesquisa'
                description: ''
                use_operator: false
                operator: search_api_fulltext_op
                identifier: search_api_fulltext
                required: true
                remember: false
                multiple: false
                remember_roles:
                  authenticated: authenticated
                  anonymous: '0'
                  administrator: '0'
                  publicador_basico: '0'
                  publicador_presi: '0'
                  jornalista: '0'
                  publicidade: '0'
                placeholder: 'Digite o termo da pesquisa'
                operator_limit_selection: false
                operator_list: {  }
              is_grouped: false
              group_info:
                label: ''
                description: ''
                identifier: ''
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: {  }
                group_items: {  }
              parse_mode: terms
              min_length: null
              fields: {  }
              plugin_id: search_api_fulltext
            created:
              id: created
              table: search_api_index_conteudo
              field: created
              relationship: none
              group_type: group
              admin_label: ''
              operator: '>='
              value:
                min: ''
                max: ''
                value: ''
                type: date
              group: 1
              exposed: true
              expose:
                operator_id: created_op
                label: 'Data inicial'
                description: ''
                use_operator: false
                operator: created_op
                identifier: initial_date
                required: false
                remember: false
                multiple: false
                remember_roles:
                  authenticated: authenticated
                  anonymous: '0'
                  administrator: '0'
                  publicador_basico: '0'
                  publicador_presi: '0'
                  jornalista: '0'
                  publicidade: '0'
                placeholder: 'Data inicial'
                min_placeholder: ''
                max_placeholder: ''
                operator_limit_selection: false
                operator_list: {  }
              is_grouped: false
              group_info:
                label: ''
                description: ''
                identifier: ''
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: {  }
                group_items: {  }
              plugin_id: search_api_date
            created_1:
              id: created_1
              table: search_api_index_conteudo
              field: created
              relationship: none
              group_type: group
              admin_label: ''
              operator: '<='
              value:
                min: ''
                max: ''
                value: ''
                type: date
              group: 1
              exposed: true
              expose:
                operator_id: created_1_op
                label: 'Data final'
                description: ''
                use_operator: false
                operator: created_1_op
                identifier: final_date
                required: false
                remember: false
                multiple: false
                remember_roles:
                  authenticated: authenticated
                  anonymous: '0'
                  administrator: '0'
                  publicador_basico: '0'
                  publicador_presi: '0'
                  jornalista: '0'
                  publicidade: '0'
                placeholder: 'Data final'
                min_placeholder: ''
                max_placeholder: ''
                operator_limit_selection: false
                operator_list: {  }
              is_grouped: false
              group_info:
                label: ''
                description: ''
                identifier: ''
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: {  }
                group_items: {  }
              plugin_id: search_api_date
            status:
              id: status
              table: search_api_index_conteudo
              field: status
              relationship: none
              group_type: group
              admin_label: ''
              operator: '='
              value: '1'
              group: 1
              exposed: false
              expose:
                operator_id: ''
                label: ''
                description: ''
                use_operator: false
                operator: ''
                identifier: ''
                required: false
                remember: false
                multiple: false
                remember_roles:
                  authenticated: authenticated
                operator_limit_selection: false
                operator_list: {  }
              is_grouped: false
              group_info:
                label: ''
                description: ''
                identifier: ''
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: {  }
                group_items: {  }
              plugin_id: search_api_boolean
            field_tags:
              id: field_tags
              table: search_api_index_conteudo
              field: field_tags
              relationship: none
              group_type: group
              admin_label: ''
              operator: or
              value: {  }
              group: 1
              exposed: true
              expose:
                operator_id: field_tags_op
                label: 'Tags de notícias'
                description: ''
                use_operator: false
                operator: field_tags_op
                identifier: field_tags
                required: false
                remember: false
                multiple: false
                remember_roles:
                  authenticated: authenticated
                  anonymous: '0'
                  administrator: '0'
                  publicador_basico: '0'
                  publicador_presi: '0'
                  jornalista: '0'
                  publicidade: '0'
                reduce: false
                operator_limit_selection: false
                operator_list: {  }
              is_grouped: false
              group_info:
                label: ''
                description: ''
                identifier: ''
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: {  }
                group_items: {  }
              reduce_duplicates: false
              type: select
              limit: true
              vid: tags
              hierarchy: false
              error_message: true
              plugin_id: search_api_term
          sorts:
            created:
              id: created
              table: search_api_index_conteudo
              field: created
              relationship: none
              group_type: group
              admin_label: ''
              order: DESC
              exposed: false
              expose:
                label: 'Ordenar por data'
              plugin_id: search_api
          title: Busca
          header: {  }
          footer: {  }
          empty:
            area_text_custom:
              id: area_text_custom
              table: views
              field: area_text_custom
              relationship: none
              group_type: group
              admin_label: ''
              empty: true
              tokenize: false
              content: 'Sua busca não retornou nenhum resultado.'
              plugin_id: text_custom
          relationships: {  }
          arguments: {  }
          display_extenders: {  }
          css_class: search-result
          use_ajax: true
          filter_groups:
            operator: AND
            groups:
              1: AND
        cache_metadata:
          max-age: -1
          contexts:
            - 'languages:language_content'
            - 'languages:language_interface'
            - url
            - url.query_args
            - user
          tags:
            - 'config:field.storage.node.body'
            - 'config:field.storage.node.field_tags'
      page_1:
        display_plugin: page
        id: page_1
        display_title: Page
        position: 1
        display_options:
          display_extenders: {  }
          path: busca
          exposed_block: false
        cache_metadata:
          max-age: -1
          contexts:
            - 'languages:language_content'
            - 'languages:language_interface'
            - url
            - url.query_args
            - user
          tags:
            - 'config:field.storage.node.body'
            - 'config:field.storage.node.field_tags'

1 Answer 1

0

One solution to this problem would be a date picker widget. This removes the need for the user to type dates in a specific format.

You should check out the Date Popup module.

Reference: milkovsky's answer to #200787

2
  • 1
    As I mentioned, Date Popup works with Search API only in the development version. In any case, I convinced the customer to use the development version, so, problem solved.
    – Deeh
    Commented Apr 29, 2020 at 12:39
  • Nice! Sorry I must have missed that when I read the question. Commented Apr 29, 2020 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.