0

I'm working on a views integration where the table and its fields are exposed to views. I want to give users the ability to filter on results of this view based on 1 of 3 fields.

I want each of the three fields in a drop down, and one text field where the user can input search terms.

Then once submitted, views will filter on the specific field and terms entered.

Is this possible? I found this discussion which has no resolution: https://drupal.org/node/732458

I'm thinking I may need to just create exposed filters for each of the three fields, and then alter the form a bit to get it how I need it.

To clarify further:

I want to expose three filters, each one searches a field by the text a user entered. I can do this in Views no problem, and it produces three distinct text fields for each of the three filters. Instead, I want the user to have just one text field, and a drop down to select which one they want to search on.

5
  • do you mean dropdown with textbox
    – Bala
    Dec 14, 2013 at 6:02
  • I clarified in a comment below.
    – Brian
    Dec 14, 2013 at 23:03
  • @Brian comments are for asking for clarifications. To provide them, edit your question.
    – Mołot
    Dec 15, 2013 at 16:36
  • @Mołot updated post
    – Brian
    Dec 15, 2013 at 21:02
  • I also need this and still not an easy way of doing it in Drupal Oct 5, 2020 at 14:55

2 Answers 2

1

You have a couple of options to do this:

  1. As you suggested just provide the user with drop-down field with the list of the criteria and single text field, then implement hook_views_query_alter where you change the where clause based on the dropdown field value. More can be found here

  2. Your second option is to use a 'Combine fields filter` with all the fields you want to search with and let the user know how your search works using a help text.

0

If I understand correctly: you want to expose 3 dropdown filters, but allow only 1 of them for input.

You can hide or show filters by using views dependent filters: https://drupal.org/project/views_dependent_filters, but then you need a filter that sets up 3 values for showing 1 of your 3 independent filters.

But, why don't you use OR instead of AND with those filters? It would give results and you can sort it as you want.

1
  • I don't want to expose three dropdown filters. I want to expose three filters, each one searches a field by the text a user entered. Normally this produces three distinct text fields, one for each field. Instead, I want the user to have just one text field, and a drop down to select which one they want to search on.
    – Brian
    Dec 14, 2013 at 23:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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