I have several exposed filters, each one has the 'optional' checkbox unchecked - therefore, they should be required. However, there is no red asterisk next to the fields, and I can submit the search without entering anything in any of the exposed widgets and I get the results. There no warning saying 'x is a required field' Users are free to search with no filters and get results that contain every single entity in the system.

Here is the query that is shown in the preview pane:

SELECT civicrm_contact.id AS id,
   users_civicrm_uf_match.name AS users_civicrm_uf_match_name,
   users_civicrm_uf_match.uid AS users_civicrm_uf_match_uid,
   node_users_civicrm_uf_match.nid AS node_users_civicrm_uf_match_nid,
   node_users_civicrm_uf_match_node_data_field_profile_image.field_profile_image_fid AS node_users_civicrm_uf_match_node_data_field_profile_image_field_profile_image_fid,
   node_users_civicrm_uf_match_node_data_field_profile_image.field_profile_image_list AS node_users_civicrm_uf_match_node_data_field_profile_image_field_profile_image_list,
   node_users_civicrm_uf_match_node_data_field_profile_image.field_profile_image_data AS node_users_civicrm_uf_match_node_data_field_profile_image_field_profile_image_data,
   node_users_civicrm_uf_match.type AS node_users_civicrm_uf_match_type,
   node_users_civicrm_uf_match.vid AS node_users_civicrm_uf_match_vid,
   civicrm_contact.display_name AS civicrm_contact_display_name,
   civicrm_address.city AS civicrm_address_city
 FROM fast_civicrm_6.civicrm_contact civicrm_contact 
 INNER JOIN fast_civicrm_6.civicrm_uf_match civicrm_uf_match ON civicrm_contact.id = civicrm_uf_match.contact_id
 INNER JOIN users users_civicrm_uf_match ON civicrm_uf_match.uf_id = users_civicrm_uf_match.uid
 INNER JOIN node node_users_civicrm_uf_match ON users_civicrm_uf_match.uid = node_users_civicrm_uf_match.uid AND node_users_civicrm_uf_match.type = 'faster_profile'
 LEFT JOIN content_field_profile_image node_users_civicrm_uf_match_node_data_field_profile_image ON node_users_civicrm_uf_match.vid = node_users_civicrm_uf_match_node_data_field_profile_image.vid
 LEFT JOIN fast_civicrm_6.civicrm_address civicrm_address ON civicrm_contact.id = civicrm_address.contact_id
 WHERE (UPPER(civicrm_contact.first_name) LIKE UPPER('%%')) AND (UPPER(civicrm_contact.last_name) LIKE UPPER('%%')) AND (users_civicrm_uf_match.status <> 0)
   ORDER BY civicrm_contact_display_name ASC

I didn't enter a default value for the filter, yet the query seems to indicate that one has been used.

I thought it may be some wierdness with the civicrm views integration, but I have tried setting up a brand new Node view, with a required exposed filter of Node Title. Same problem. It is not required at all, and users can submit the search without entering anything in the exposed filter.

possibly related to:
#286662: Exposed filters always use default value
#465158: No search results with exposed "search terms" filter

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mrfelton’s picture

bump* any ideas?

Cyberwolf’s picture

Subscribing

dawehner’s picture

@Merlinofchaos are you ok with writing a patch?

This might need quite a lot of code change because every value form might be have to be changed.

Alternative exposed_form could change it after calling value_form.

merlinofchaos’s picture

The only thing that 'optional' means is that "Any" will be added an option.

The red asterisk cannot be added because FAPI processes this even when you don't want to, so we cannot use #required => TRUE ever. As a matter of course I have moved away from ever using it. This is not a feature Views can support.

It's possible that the 'optional' checkbox should not appear on string filters.

dawehner’s picture

Status: Active » Needs review
FileSize
879 bytes

Here is a patch for this. I'm not sure wether the option definition should be removed or defaulted to FALSE.

merlinofchaos’s picture

I would say to set it to FALSE rather than unsetting it. It seems safer.

dawehner’s picture

Assigned: Unassigned » dawehner

assingn to myself

dawehner’s picture

FileSize
880 bytes

New patch

dawehner’s picture

Assigned: dawehner » Unassigned
dawehner’s picture

Here is a new version which uses a flag on the object itself.

Added some documentation for the flags.

merlinofchaos’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
Status: Needs review » Patch (to be ported)

Committed to 2.x and 3.x -- doesn't quite apply to 7.x

dawehner’s picture

Status: Patch (to be ported) » Fixed

Ported to 7.x

iStryker’s picture

Priority: Normal » Critical
Status: Fixed » Needs work

This patch broke my views.

This patch removed the optional checkbox, when I wanted things to be optional. I believe it did it only for string filters. My location exposed filter did not break.

Everything was fixed for me, when I reversed this patch back from views-6.x-3.x-dev (feb 13th).

SELECT users.picture AS users_picture,
users.uid AS uid,
users.name AS users_name,
users.mail AS users_mail,
profile_values_profile_last_name.value AS profile_values_profile_last_name_value,
profile_values_profile_last_name.uid AS profile_values_profile_last_name_uid,
profile_values_profile_first_name.value AS profile_values_profile_first_name_value,
profile_values_profile_first_name.uid AS profile_values_profile_first_name_uid,
node_users.type AS node_users_type,
node_users.nid AS node_users_nid,
node_users.vid AS node_users_vid,
node_users_node_data_field_personal_location.field_personal_location_lid AS node_users_node_data_field_personal_location_field_personal_,
users.access AS users_access,
users.created AS users_created
FROM users users
LEFT JOIN node node_users ON users.uid = node_users.uid AND node_users.type = 'profile'
LEFT JOIN content_field_job_title node_users_node_data_field_job_title ON node_users.vid = node_users_node_data_field_job_title.vid
LEFT JOIN content_field_organization node_users_node_data_field_organization ON node_users.vid = node_users_node_data_field_organization.vid
LEFT JOIN profile_values profile_values_profile_first_name ON users.uid = profile_values_profile_first_name.uid AND profile_values_profile_first_name.fid = '1'
LEFT JOIN profile_values profile_values_profile_last_name ON users.uid = profile_values_profile_last_name.uid AND profile_values_profile_last_name.fid = '2'
LEFT JOIN content_type_profile node_users_node_data_field_personal_location ON node_users.vid = node_users_node_data_field_personal_location.vid
WHERE (UPPER(node_users_node_data_field_job_title.field_job_title_value) LIKE UPPER('%%')) AND (UPPER(node_users_node_data_field_organization.field_organization_value) = UPPER('')) AND (UPPER(profile_values_profile_first_name.value) LIKE UPPER('%%')) AND (UPPER(profile_values_profile_last_name.value) LIKE UPPER('%%')) AND (users.status <> 0)

dagmar’s picture

Priority: Critical » Normal
Status: Needs work » Fixed

Yes, the patch to fix this issue is here: #1054272: String filters are non optional anymore

iStryker’s picture

Status: Fixed » Closed (fixed)

Thanks dagmar. That new issue addresses the new bug when this patch was committed. I"m going to close this issue

JayKayAu’s picture

Hangon, so there's some technical reason to do with FAPI why a textfield filter can't be "required", is that right?

So how can I get the view to show nothing if the textfield is left empty? This seems to be a valid use case, so is there a workaround?