Vikas Naranje
Vikas Naranje

Reputation: 2402

drupal exposed filter "is empty (NULL)" dropdown not working

I've a content type which content some cck field. One of the field has type text and it's not required field. So it depends on user whether he/she wants to fill this field or not.

I've created a view to display all records with this field as exposed filter which is optional. When I want to apply filter "is empty (NULL)" from dropdown it's showing me mix records. But I intended to get only those records in which this column value is NULL/EMPTY.

How can I configure my view Or apply changes to get desired record after filter.

Upvotes: 2

Views: 2954

Answers (2)

Vikas Naranje
Vikas Naranje

Reputation: 2402

Answering own question :

I think that it's a bug in drupal exposed filter when you select [IS EMPTY (NULL)] from operator. What drupal do is actually hide the textbox. And when you hit the apply button because of this textbox is empty, it does not included in view query's where clause

After some search and analysis what i found is -

In this file - sites/all/modules/views/js/dependent.js

If you make change where i placed comment

var setChangeTrigger = function(trigger_id, bind_id) {
    var changeTrigger = function() {

    .....

    if (rel_num <= len) {
        // Show if the element if criteria is matched
        $(object).children(':input').val('');  
        // EMPTYING THE TARGETED DROPDOWN ON CHANGE
        object.show(0);
        object.addClass('dependent-options');
    }
    else {
        // Otherwise hide

        $(object).children(':input').val('uw'); 
        // PUTTING ANY CHARACTER, WHEN CHANGED EVENT IS CALLED 
        // AND FROM OPERATOR YOU CHOSE IS EMPTY (NULL). 
        // IN MY CASE I JUST PUT "uw"
        object.hide(0);
    } 

you will get the desired result which i was seeking.

You can verify this using hook__views_pre_execute()

function myModule_views_pre_execute(&$view){
    switch($view->name)
    {
        case 'YOUR VIEW NAME':
            drupal_set_message($view->build_info['query']);
        break;
    }
} 

Upvotes: 1

Sibiraj PR
Sibiraj PR

Reputation: 1481

This field can set some default value such as 0 or somethings like that form the back end (cck manage

Upvotes: 0

Related Questions