Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.4] Fix SQL field, get the filter value from the linked filter field #43789

Merged
merged 5 commits into from
Aug 5, 2024

Conversation

Fedik
Copy link
Member

@Fedik Fedik commented Jul 13, 2024

Summary of Changes

Due to bug in SQL field the feature "Linked Fields as Filters" is broken.
The PR is fixing this feature, by using the value directly from the form.
Use of the value from Request should be deprecated in future.

Thanks @robbiejackson for the idea and code. I just copy pasting it in to the PR :)

Testing Instructions

Add folowing field in to Custom HTML module:

<field
  name="catid"
  type="sql"
  label="Category"
  sql_select="id, title"
  sql_from="#__categories"
  sql_where="level=1 AND extension='com_content'"
  sql_order="lft"
  key_field="id"
  value_field="title"
  default="2"
  onchange="window['toolbar-apply'].buttonElement.click()"
>
  <option>- Select -</option>
</field>
<field
  name="subcat"
  type="sql"
  label="Article"
  sql_select="id, title"
  sql_from="#__content"
  sql_order="title"
  sql_filter="catid"
  key_field="id"
  value_field="title"
>
  <option>- Select -</option>
</field>

Create and save new Custom HTML module, or open existing.
Change the value of "Category" field.
After selecting new value and saving the form, the linked Article field should display only articles from the selected category.

Actual result BEFORE applying this Pull Request

The Article field shows ALL articles.

Expected result AFTER applying this Pull Request

The Article field shows only the articles froms the selected category.

Link to documentations

Please select:

@Fedik Fedik added the bug label Jul 13, 2024
@Fedik Fedik changed the title [4.0] Fix SQL field, get the filter value from the linked filter field [4.4] Fix SQL field, get the filter value from the linked filter field Jul 13, 2024
@robbiejackson
Copy link

robbiejackson commented Jul 14, 2024

I've updated the documentation for the SQL form field to describe the Linked Field feature at http://pr-278.manual.joomlacode.org/docs/next/general-concepts/forms-fields/standard-fields/sql#linked-fields-as-filters (it's not yet merged into the Joomla Manual).

The documentation uses the example of a category field, and a SQL field which displays the titles of articles whose category matches that of the category field.

The documentation includes (at the bottom of the page) a link to a component com_sqlfield which can be downloaded and adapted for testing this PR.

The current version of the SQL field uses the user state to pass the linked field id to the SQL field (eg the category id to the SQL field displaying the list of titles). This involves:

  • setting the 'context' attribute on the linked field
  • setting the user state against the <context>.filter in the Controller, to pass the linked field id to the SQL field

It's a lot easier for the user if the SQL field code gets the linked field id from the Form object, rather than requiring the user to explicitly pass it in a state variable.

The com_sqlfield component still works when this PR is applied, showing that if someone has used the user state method to implement this feature then it should be backward compatible.

To test this PR I removed the 'context' attribute from the sql field in the xml form, and the setting of the "sqlfield.filter" state in the SqlfieldController and the component worked ok.

I'll update the documentation if this PR gets merged.

@robbiejackson
Copy link

I have tested this item ✅ successfully on 1febcaf

Just confirming the above tests by following the proper procedure.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43789.

@viocassel
Copy link
Contributor

I have tested this item ✅ successfully on 1febcaf


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43789.

@Quy
Copy link
Contributor

Quy commented Jul 22, 2024

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43789.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jul 22, 2024
@MacJoom MacJoom self-assigned this Aug 5, 2024
@MacJoom MacJoom added this to the Joomla! 4.4.7 milestone Aug 5, 2024
@MacJoom MacJoom merged commit c73f790 into joomla:4.4-dev Aug 5, 2024
3 checks passed
@MacJoom
Copy link
Contributor

MacJoom commented Aug 5, 2024

Thank you!

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Aug 5, 2024
@Fedik Fedik deleted the fix-sql-filter-field branch August 5, 2024 14:55
dgrammatiko pushed a commit to dgrammatiko/joomla-cms that referenced this pull request Aug 11, 2024
joomla#43789)

* Fix SQL field, get the filter value from the linked filter field

* cs

* esc

---------
dgrammatiko pushed a commit to dgrammatiko/joomla-cms that referenced this pull request Aug 11, 2024
joomla#43789)

* Fix SQL field, get the filter value from the linked filter field

* cs

* esc

---------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants