? Pending

User tests: Successful: Unsuccessful:

avatar richard67
richard67
27 Dec 2019

Pull Request for Issue #20853 .

Summary of Changes

Make it possible to use "onchange" events for switcher fields (type="radio", class="switcher").

There was once opened issue #20853 for "onchange" and "onclick" events, which was closed because PR #20931 was made for the CMS.

This PR then was closed because a PR against the backend template repo was made: joomla/40-backend-template#446.

This then was merged into the backend template but either never found the way to the CMS or was later removed by some other change.

This PR here brings the correction back, but only for "onchange", not for "onclick", because to click on a switcher always means to change the value, and because we also don't have the "onclick" event on list fields.

The change does it in a bit different way than #20931 and joomla/40-backend-template#446, so it is closer to the existing implementation in other field layouts.

In addition to the "onchange" property, this PR also adds the "id" property.

Testing Instructions

  1. Make sure that your web browser allows popup alerts for your Joomla backend.

  2. Edit some form XML and add an onchange event to a switcher field.
    E.g. you can edit file "administrator/components/com_config/forms/application.xml" and modify field name="gzip" by adding an "onchange" property for a javascript alert as follows:

<field
	name="gzip"
	type="radio"
	label="COM_CONFIG_FIELD_GZIP_COMPRESSION_LABEL"
	class="switcher"
	default="0"
	filter="boolean"
	onchange="alert('Hello, I am a switcher field.')"
	>
	<option value="0">JNO</option>
	<option value="1">JYES</option>
</field>
  1. Go to a page where you can see the switcher field modified in step 2 and toggle the field.
    E.g. if you used the field suggested in step 2: Go to the "Server" tab of "Global Configuration" in backend and toggle the "Gzip Page Compression" switcher field.
    Result: No browser alert, see section "Actual result" below..

  2. In developer tools of your web browser, inspect html of the switcher element ("fieldset" html element).
    Result: No "onchange" property added to fieldset, see section "Actual result" below.

  3. Apply the patch of this PR.

  4. Go to some other page and then back, e.g. if you used "Global Configuration" close it and then open it again, and toggle the switcher field.
    Result: See section "Expected result" below.

  5. In developer tools of your web browser, inspect html of the switcher element ("fieldset" html element).
    Result: See section "Expected result" below.

Expected result

Onchange event works:

switcher-3

Fieldset has "id" and "onchange" properties:

switcher-2

Actual result

Onchange event doesn't work.

Fieldset doesn't have "id" and "onchange" properties:

switcher-1

Documentation Changes Required

Not sure. Maybe some doc about fields tells onchange is not supported for switchers?

avatar richard67 richard67 - open - 27 Dec 2019
avatar richard67 richard67 - change - 27 Dec 2019
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 27 Dec 2019
Category Layout
avatar richard67
richard67 - comment - 27 Dec 2019

Drone failure seems to be the usual, randomly occurring timeout on mysql system tests and so not to be related to this PR.

avatar richard67 richard67 - change - 27 Dec 2019
The description was changed
avatar richard67 richard67 - edited - 27 Dec 2019
avatar richard67 richard67 - change - 27 Dec 2019
The description was changed
avatar richard67 richard67 - edited - 27 Dec 2019
avatar richard67 richard67 - change - 27 Dec 2019
The description was changed
avatar richard67 richard67 - edited - 27 Dec 2019
avatar richard67 richard67 - change - 27 Dec 2019
The description was changed
avatar richard67 richard67 - edited - 27 Dec 2019
avatar richard67 richard67 - change - 27 Dec 2019
The description was changed
avatar richard67 richard67 - edited - 27 Dec 2019
avatar richard67 richard67 - change - 27 Dec 2019
The description was changed
avatar richard67 richard67 - edited - 27 Dec 2019
avatar richard67 richard67 - change - 28 Dec 2019
Labels Added: ?
avatar richard67 richard67 - change - 28 Dec 2019
The description was changed
avatar richard67 richard67 - edited - 28 Dec 2019
avatar richard67
richard67 - comment - 29 Dec 2019

@brianteeman I'd be happy if you could find some time for testing this. It's an easy test for a small change.

avatar Quy Quy - test_item - 29 Dec 2019 - Tested successfully
avatar Quy
Quy - comment - 29 Dec 2019

I have tested this item successfully on 765163b


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

avatar richard67
richard67 - comment - 30 Dec 2019

@SharkyKZ I've removed disabled and readonly stuff so this PR does not more than the description says. Someone else may later add back these in the right way and maybe add more properties if necessary with a new PR.

@Quy Could you test again?

avatar richard67 richard67 - change - 30 Dec 2019
The description was changed
avatar richard67 richard67 - edited - 30 Dec 2019
avatar HLeithner HLeithner - change - 30 Dec 2019
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2019-12-30 11:40:28
Closed_By HLeithner
avatar HLeithner HLeithner - close - 30 Dec 2019
avatar HLeithner HLeithner - merge - 30 Dec 2019
avatar HLeithner
HLeithner - comment - 30 Dec 2019

Quy test is valid and merge by code review

avatar HLeithner
HLeithner - comment - 30 Dec 2019

Thanks

avatar richard67
richard67 - comment - 30 Dec 2019

Thanks too to testers and mergers ;-)

Add a Comment

Login with GitHub to post a comment