RTC PBF bug Small PR-4.4-dev Pending

User tests: Successful: Unsuccessful:

avatar heelc29
heelc29
2 Jan 2023

Pull Request for Issue #37851 .

Summary of Changes

Adds an id attribute to the hidden input element when a list field is read-only
The id attribute is required for the showon function as it uses the field's id to get the value.

itemval = document.getElementById(originId).value;

In the core I do not find this situation but a workaround for that case (added with #33096). Here the showon attribute is cleared or the field removed ...

// In case we are editing a field, field type cannot be changed, so some extra handling below is needed
if ($fieldId) {
$fieldType = $form->getField('type');
if ($fieldType->value == 'subform') {
// Only Use In subform should not be available for subform field type, so we remove it
$form->removeField('only_use_in_subform');
} else {
// Field type could not be changed, so remove showon attribute to avoid js errors
$form->setFieldAttribute('only_use_in_subform', 'showon', '');
}
}

Testing Instructions

Add following code to administrator/components/com_content/forms/article.xml

image

copy template:

<fieldset name="showontest" label="SHOWONTEST">
	<field
		name="list1"
		type="list"
		label="LIST ENABLE"
		default="0"
		>
		<option value="0">VALUE 0</option>
		<option value="1">VALUE 1</option>
	</field>
	<field
		name="text1"
		type="text"
		label="TEXT 1"
		showon="list1:1"
	/>
	<field
		name="list2"
		type="list"
		label="LIST DISABLE"
		default="0"
		readonly="true"
		>
		<option value="0">VALUE 0</option>
		<option value="1">VALUE 1</option>
	</field>
	<field
		name="text2"
		type="text"
		label="TEXT 2"
		showon="list2:1"
	/>
</fieldset>
  • visit site to add a new article
  • check output and browsers debug console

Actual result BEFORE applying this Pull Request

A js error exists because getElementById fails:
image

  • field TEXT1 is only visible when field LIST ENABLE have value VALUE 1
  • field TEXT2 is visible but should not
    image

Expected result AFTER applying this Pull Request

No longer a js error

  • field TEXT1 is only visible when field LIST ENABLE have value VALUE 1
  • field TEXT2 is not visible because field LIST DISABLE have value VALUE 0
    image

Link to documentations

Please select:

  • No documentation changes for docs.joomla.org needed
  • No documentation changes for manual.joomla.org needed
avatar joomla-cms-bot joomla-cms-bot - change - 2 Jan 2023
Category Layout
avatar heelc29 heelc29 - open - 2 Jan 2023
avatar heelc29 heelc29 - change - 2 Jan 2023
Status New Pending
avatar heelc29 heelc29 - change - 3 Jan 2023
Labels Added: ?
avatar heelc29
heelc29 - comment - 15 Jan 2023

@dgrammatiko Can you support me here? I have a problem when the multiple attr is set. You solved a similar problem with #35723. Thanks in advance.

avatar dgrammatiko
dgrammatiko - comment - 15 Jan 2023

Try changing

} else if (originField.nodeName === 'SELECT' && originField.hasAttribute('multiple')) {
to:

} else if (originField.nodeName === 'SELECT' && originField.hasAttribute('multiple') && !originField.hasAttribute('disabled')) {

I haven't tested the code, maybe you can share some subform to make debugging easier

avatar heelc29
heelc29 - comment - 16 Jan 2023

Try changing

@dgrammatiko I think it don't work because the originField is no longer a select
image

<div class="controls">
	<select id="jform_list4" name="" class="form-select" multiple="" disabled="disabled">
		<option value="0" disabled="disabled" selected="selected">VALUE 0</option>
		<option value="1" disabled="disabled">VALUE 1</option>
		<option value="2" disabled="disabled" selected="selected">VALUE 2</option>
	</select>
	<input type="hidden" name="jform[list4][]" value="0">
	<input type="hidden" name="jform[list4][]" value="2">
</div>

I haven't tested the code, maybe you can share some subform to make debugging easier

I added this to administrator/components/com_content/forms/article.xml
image

debug code
<fieldset name="showontest" label="SHOWONTEST">
	<field
		name="list1"
		type="list"
		label="LIST ENABLE"
		default="0"
		>
		<option value="0">VALUE 0</option>
		<option value="1">VALUE 1</option>
	</field>
	<field
		name="text1"
		type="text"
		label="TEXT 1"
		showon="list1:1"
	/>
	<field
		name="list2"
		type="list"
		label="LIST DISABLE"
		default="0"
		readonly="true"
		>
		<option value="0">VALUE 0</option>
		<option value="1">VALUE 1</option>
	</field>
	<field
		name="text2"
		type="text"
		label="TEXT 2"
		showon="list2:1"
	/>

	<field
		name="list3"
		type="list"
		label="LIST ENABLE MULT"
		multiple="true"
		default="[0,2]"
		>
		<option value="0">VALUE 0</option>
		<option value="1">VALUE 1</option>
		<option value="2">VALUE 2</option>
	</field>
	<field
		name="text3"
		type="text"
		label="TEXT 3"
		showon="list3:1"
	/>
	<field
		name="list4"
		type="list"
		label="LIST DISABLE MULT"
		multiple="true"
		default="[0,2]"
		readonly="true"
		>
		<option value="0">VALUE 0</option>
		<option value="1">VALUE 1</option>
		<option value="2">VALUE 2</option>
	</field>
	<field
		name="text4"
		type="text"
		label="TEXT 4"
		showon="list4:1"
	/>
</fieldset>
avatar HLeithner
HLeithner - comment - 2 May 2023

This pull request has been automatically rebased to 4.3-dev.

avatar heelc29 heelc29 - change - 2 May 2023
Labels Added: bug ?
avatar heelc29 heelc29 - change - 2 May 2023
Title
[4.2] Fix showon for list field
[4.3] Fix showon for list field
avatar heelc29 heelc29 - edited - 2 May 2023
avatar heelc29 heelc29 - change - 20 May 2023
Labels Added: PR-4.3-dev
Removed: ?
avatar HLeithner
HLeithner - comment - 30 Sep 2023

This pull request has been automatically rebased to 4.4-dev.

avatar Hackwar
Hackwar - comment - 21 Feb 2024

Could you make this PR ready so that we can test this during PBF?

avatar heelc29 heelc29 - change - 22 Feb 2024
The description was changed
avatar heelc29 heelc29 - edited - 22 Feb 2024
avatar heelc29 heelc29 - change - 22 Feb 2024
Title
[4.3] Fix showon for list field
[4.4] Fix showon for list field
Labels Added: Small PR-4.4-dev
Removed: PR-4.3-dev ?
avatar heelc29 heelc29 - change - 22 Feb 2024
Title
[4.4] Fix showon for list field
[4.4] Fix showon for list field (no multiple)
avatar heelc29 heelc29 - edited - 22 Feb 2024
avatar heelc29
heelc29 - comment - 22 Feb 2024

@Hackwar I've updated the testing instructions.

avatar TLWebdesign TLWebdesign - test_item - 24 Feb 2024 - Tested successfully
avatar TLWebdesign
TLWebdesign - comment - 24 Feb 2024

I have tested this item ✅ successfully on 91bc2cd

Tested Successfully


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

avatar tomsrocket tomsrocket - test_item - 24 Feb 2024 - Tested successfully
avatar tomsrocket
tomsrocket - comment - 24 Feb 2024

I have tested this item ✅ successfully on 91bc2cd


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

avatar richard67 richard67 - change - 24 Feb 2024
Status Pending Ready to Commit
avatar richard67
richard67 - comment - 24 Feb 2024

RTC


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

avatar MacJoom MacJoom - change - 28 Feb 2024
Labels Added: RTC PBF
avatar laoneo laoneo - change - 1 Mar 2024
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2024-03-01 06:18:27
Closed_By laoneo
avatar laoneo laoneo - close - 1 Mar 2024
avatar laoneo laoneo - merge - 1 Mar 2024
avatar laoneo
laoneo - comment - 1 Mar 2024

Thanks!

Add a Comment

Login with GitHub to post a comment