3

Having followed the excellent explanation for How to create a view with filters and pagination, I have a custom field that filters for the most part. As it is, the code in the custom field is retrieving the filtering data from what is posted via jInput, and it works splendidly. However, if the user returns to the page (without the filtering data being posted), then Search Tools detects that there is an active filter, thus shows, but does not populate the form with the filter data (it's not in the post, thus nothing to populate the form with).

Clearly, I should be retrieving the filtering data from somewhere else, apparently the form, but I can't figure out how to get to it. In the custom field form code, I can see the filters and data, but can't figure out the correct method(s) to get to it in order to fill the form before rendering.

So from the custom fields $this, how do I get to the protected form, then to the protected registry object, and ultimately to the protected data/filter as shown below?

JFormFieldMyCustomField Object
(
    [type:protected] => mycustomfield
    [input_type:JFormFieldMycustomfield:private] => 
    .
    .
    .
    [form:protected] => JForm Object (
            [data:protected] => Joomla\Registry\Registry Object (
                    [data:protected] => stdClass Object  (
                            [filter] => stdClass Object (
                                    [search] => 
                                    [myfield2] => 95
                                    [myfield1] => Array (
                                            [0] => 4
                                            [1] => 5
                                            [2] => 6
                                            [3] => 37
                                        )
                                )
                        )
3

Thank God for 5 year old posts and Occam's Razor. The Custom Field has direct access to the form that I was trying to get to!!!! No need to load a model, helper, or otherwise.

$MyField1 = $this->form->getData()->get('filter',array())->myfield1;
$MyField2 = $this->form->getData()->get('filter',array())->myfield2;

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.