Initial_filter for pupup

@waraikobuot, let me understand the problem, what are the modules you are working on, custom and…? What are you trying to achieve? Where are you making the changes?

I created total of 4 modules all of them are customs. I have a Location, Province, City and Barangay.

In location module I have 3 field a Province(Relate to Province Module), City(Relate to City Module) and Barangay(Relate to Barangay Module). If you click Province Field on the City Field there must be a Pre-filtered result. Check my sample result below:
image

This logic is working now using this code below: (But the data/result are not clickable)

if(!empty($_REQUEST['city'])){
    $parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
    $_REQUEST['request_data'] = $_REQUEST['city'];
}else{
    $parameters_advanced='`dvt3_city_id_c`="'. $_REQUEST['request_data'].'"';// example part of SQL WHERE
}

For the Changes I added a displayparams on Custom Location Module
For City Relate Field in Location Module

            'name' => 'custom_city_c',
            'studio' => 'visible',
            'label' => 'LBL_CITY',
            'displayParams' => array(
                'initial_filter' => '&province="+this.form.{$fields.dvt2_province_id_c.name}.value+"&province_name="+this.form.{$fields.custom_province_c.name}.value+"',
              ),

For Barangay Relate Field in Location Module

'name' => 'custom_barangay_c',
            'studio' => 'visible',
            'label' => 'LBL_BARANGAY',
            'displayParams' => array(
              'initial_filter' => '&province_name="+this.form.{$fields.custom_province_c.name}.value+"&city="+this.form.{$fields.dvt3_city_id_c.name}.value+"&city_name="+this.form.{$fields.custom_city_c.name}.value+"',
             ),

And I modify the popupdefs for City and Barangay Module. Check the code below:

if(!empty($_REQUEST['city'])){
    $parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
    $_REQUEST['request_data'] = $_REQUEST['city'];
}else{
    $parameters_advanced='`dvt3_city_id_c`="'. $_REQUEST['request_data'].'"';// example part of SQL WHERE
}
$popupMeta = array (
    'moduleMain' => 'dvt4_Barangay',
    'varName' => 'dvt4_Barangay',
    'orderBy' => 'dvt4_barangay.name',
    'whereStatement'=> "$parameters_advanced",
    'whereClauses' => array (
    'name' => 'dvt4_barangay.name',
),
    'searchInputs' => array (
  1 => 'name',
),
  'searchdefs' => array (
  'custom_province_c' =>
  array (
    'type' => 'readonly',
    'studio' => 'visible',
    'label' => 'LBL_PROVINCE',
    'id' => 'DVT2_PROVINCE_ID_C',
    'width' => '10%',
    'name' => 'custom_province_c',
    'value' =>''.$_REQUEST['province_name'].'',
  ),
  'custom_city_c' =>
  array (
    'type' => 'readonly',
    'studio' => 'visible',
    'label' => 'LBL_CITY',
    'id' => 'DVT3_CITY_ID_C',
    'width' => '10%',
    'name' => 'custom_city_c',
    'value' =>''.$_REQUEST['city_name'].'',
  ),
  'name' =>
  array (
    'name' => 'name',
    'width' => '10%',
  ),
),
    'listviewdefs' => array (
  'NAME' => 
  array (
    'width' => '32%',
    'label' => 'LBL_NAME',
    'default' => true,
    'link' => true,
    'name' => 'name',
  ),
  'CUSTOM_CITY_C' => 
  array (
    'type' => 'relate',
    'studio' => 'visible',
    'label' => 'LBL_CITY',
    'id' => 'DVT3_CITY_ID_C',
    'width' => '10%',
    'default' => true,
    'name' => 'custom_city_c',
  ),
  'CUSTOM_PROVINCE_C' => 
  array (
    'type' => 'relate',
    'studio' => 'visible',
    'label' => 'LBL_PROVINCE',
    'id' => 'DVT2_PROVINCE_ID_C',
    'width' => '10%',
    'default' => true,
    'name' => 'custom_province_c',
  ),
),

Samples result are correct already but the problem is when I click the result I am unable to populate the result to the barangay field. As you can see the image bellow the field is still empty.

So, you

  • choose the province
  • the popup appears
  • you select the province
  • and automatically you would like to populate the Barangay and City fields?

Yes sir that`s correct. I was able to populate it but I am unable to choose city and province. when I am using this code below:

if(!empty($_REQUEST['city'])){
    $parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
    $_REQUEST['request_data'] = $_REQUEST['city'];
}else{
    $parameters_advanced='`dvt3_city_id_c`="'. $_REQUEST['request_data'].'"';// example part of SQL WHERE
}


Error when clicking the result data

But if I used this code I can choose city and barangay. The only problem is, it has a bug the search is not working. If you click search and input the name value the result will be empty.

if(!empty($_REQUEST['city'])){
    $parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
}else{
    $parameters_advanced='`dvt3_city_id_c`=" "'; // example part of SQL WHERE
}

And I wan`t also to retain the value also make it uneditable input field on the popupdef since it is my pre-filtered data

to populate the fields as you want them, you have to act on editviewdefs.

this code

if(!empty($_REQUEST['city'])){
    $parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
    $_REQUEST['request_data'] = $_REQUEST['city'];
}else{
    $parameters_advanced='`dvt3_city_id_c`="'. $_REQUEST['request_data'].'"';// example part of SQL WHERE
}

is for the initial popup filter, but if you want interdependent fields you need to open editviewdefs.php and find the field of interest (provinces) and enter something like this

 'displayParams' => 
            array (             
              'field_to_name_array' => 
              array (               
                'province_city' => 'city', //to the left the current field=>to the right the destination field            
                'id' => 'city_id',
              ),
            ),

@fab , so you mean I will change in the editview initial_filter?

From this:

'displayParams' => array(
                'initial_filter' => '&dvt2_province_id_c_advanced="+this.form.{$fields.dvt2_province_id_c.name}.value+"&custom_province_c_advanced="+this.form.{$fields.custom_province_c.name}.value+"',
              ),

To this:

'displayParams' => 
            array (             
              'field_to_name_array' => 
              array (               
                'province_city' => 'city', //to the left the current field=>to the right the destination field            
                'id' => 'city_id',
              ),
            ),

No, you have to add it:

'displayParams' => 
            array (       
              'initial_filter' => '&dvt2_province_id_c_advanced="+this.form.{$fields.dvt2_province_id_c.name}.value+"&custom_province_c_advanced="+this.form.{$fields.custom_province_c.name}.value+"',
              'field_to_name_array' => 
              array (               
                'province_city' => 'city', //to the left the current field=>to the right the destination field            
                'id' => 'city_id',
              ),
            ),

I am a little bit confuse on this

'province_city' => 'city', //to the left the current field=>to the right the destination field            
'id' => 'city_id',

province_city is the name of my province field and same to city?

province_city is the field name of the provinces module (the result of the choice with the arrow), within the Province module you will have a field named city (this is the field you will need to consider), city is the destination field, that is, the result of the popup (city of the Province module) will go to fill the city field of the current module (in your case, the Location module).

@fab , noted on this. Btw I have a question it is possible to set the pre-filtered field as readonly in popupdef and the clear button? Because I wan`t to exclude the pre-filtered field to be cleared once you clear the clear button.

Sorry, I don’t know how to make it readonly inside the popup, but by setting the initial filter in popudefs, even if you delete the field, it should remain unchanged

@fab , ow probably that is the best option if it is impossible to set the field as readonly, we can remove the field itself. Actually I need to make the field un-editable and it should be excluded on the clear button but if I am not mistaken it will have a lot of work to do in terms of modification.