User tests: Successful: Unsuccessful:
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 :)
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.
The Article field shows ALL articles.
The Article field shows only the articles froms the selected category.
Please select:
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Title |
|
Labels |
Added:
bug
PR-4.4-dev
|
I have tested this item ✅ successfully on 1febcaf
Just confirming the above tests by following the proper procedure.
I have tested this item ✅ successfully on 1febcaf
Status | Pending | ⇒ | Ready to Commit |
RTC
Labels |
Added:
RTC
|
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-08-05 14:48:00 |
Closed_By | ⇒ | MacJoom |
Thank you!
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:
<context>.filter
in the Controller, to pass the linked field id to the SQL fieldIt'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.