1

Content type has two fields: Property type and bedroom.

I created a view where above fields were exposed to visitors.

When I visit my site, I see -Any - is the default value for the both fields. First field is the property type and the second field is the bedroom field.

enter image description here

enter image description here

Property type field :

enter image description here

Bedroom field:

enter image description here

How can I replace the default value -Any - by the corresponding field label? For example, for property type field, I like to see Property Type as the default value and for the bedroom field, I like to see bedroom as the default value in the drop down list.

2

You can change it with custom code in a module or overriding your theme.

You can also use the Better Exposed Filters module. Change the Exposed form options in your Views to use that module option. Then in the further settings you'll be able to override what the options are called for each filter separately.

Drupal 7 also had Views Advanced Labels.

Use this field to rewrite the filter options displayed. Use the format of current_text|replacement_text, one replacement per line. For example:

 Current|Replacement  
 On|Yes
 Off|No

Leave the replacement text blank to remove an option altogether.

| improve this answer | |
  • This is for D8. Can you please provide some details about the custom code as well? – Kaimei Wang Aug 12 at 21:44
  • You would have to implement hook_form_FORM_ID_alter for views_exposed_form. Better Exposed Filters is a great little module to handle this with configuration though! – sonfd Aug 13 at 2:39
0

As stated by prkos in his comment (sorry, I don't have enough reputation to reply to his comment), you could benefit of Better Exposed Filters. What you would need to do is:

  1. Enable Better Exposed Filters and clear the cache
  2. In your view, open the Advanced section > Exposed Form > select 'Better Exposed Filters'
  3. On the settings Exposed Form > Exposed form Style > Settings, go down and find your exposed filter
  4. Expand your filter and rewrite the '- Any -' as this: - Any -|Bedrooms
  5. That will change the LABEL of the select option, but the value will always be 'All' unless you change it via code. If code is what you need, please say so and I will try to provide a useful snippet.
| improve this answer | |

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.