No Code Attached Yet
avatar ryanminnig
ryanminnig
2 Aug 2023

Steps to reproduce the issue

In an arbitrary form definition XML file, add 1 of the 3 variations for the field for a color picker:

Variation 1

<field 
name="color" 
type="color" 
default="rgba(255, 40, 40, 0.5)" 
format="rgba" 
label="FORM_LBL_MAP_COLOR"   
hint="FORM_LBL_MAP_COLOR" />

Variation 2

<field 
name="color" 
type="color" 
default="rgba(255, 40, 40, 0.5)" 
format="rgba" 
label="FORM_LBL_MAP_COLOR"   
hint="FORM_LBL_MAP_COLOR" 
onchange="(function(){console.log('onchange triggered')})()"/>

Variation 3

<field 
name="color" 
type="color" 
default="rgba(255, 40, 40, 0.5)" 
format="rgba" 
label="FORM_LBL_MAP_COLOR"   
hint="FORM_LBL_MAP_COLOR" 
onchange=" onchange=&quot;(function(){console.log('change')})()&quot;"/>

Expected result

Variation 1 - Works as expected

<input type="text" name="jform[color]" id="jform_color" value="rgba(255, 48, 41, 0.5)" placeholder="FORM_LBL_MAP_COLOR" class="form-control minicolors rgba minicolors-input" data-position="default" data-control="hue" data-format="rgba" size="25" data-opacity="0.50">

Variation 2 - should render the onchange properly

<input type="text" name="jform[color]" id="jform_color" value="rgba(255, 48, 41, 0.5)" placeholder="FORM_LBL_MAP_COLOR" class="form-control minicolors rgba minicolors-input" data-position="default" data-control="hue" onchange="(function(){console.log('change')})()" data-format="rgba" size="25" data-opacity="0.50">

Actual result

Variation 1 - Works as expected

<input type="text" name="jform[color]" id="jform_color" value="rgba(255, 48, 41, 0.5)" placeholder="FORM_LBL_MAP_COLOR" class="form-control minicolors rgba minicolors-input" data-position="default" data-control="hue" data-format="rgba" size="25" data-opacity="0.50">

No console activity is expected.

Variation 2 - the onchange is not rendered properly, note: onchange= is missing after "hue"

<input type="text" name="jform[color]" id="jform_color" value="rgba(255, 48, 41, 0.5)" placeholder="FORM_LBL_MAP_COLOR" class="form-control minicolors rgba minicolors-input" data-position="default" data-control="hue" (function(){console.log('onchange="" triggered')})()="" data-format="rgba" size="25" data-opacity="0.50">

It is expected to see "change" logged to the console, but it does not

Variation 3 - the desired rendering of the field is achieved by tricking the form parameters

<input type="text" name="jform[color]" id="jform_color" value="rgba(255, 48, 41, 0.5)" placeholder="FORM_LBL_MAP_COLOR" class="form-control minicolors rgba minicolors-input" data-position="default" data-control="hue" onchange="(function(){console.log('change')})()" data-format="rgba" size="25" data-opacity="0.50">

It is expected to see "change" logged to the console and it is

System information (as much as possible)

Joomla 4.3.3 (also the same behavior on Joomla 4.2.2)

Additional comments

<field 
name="color" 
type="color" 
default="rgba(255, 48, 41, 0.5)" 
format="rgba" 
label="FORM_LBL_MAP_COLOR" 
hint="FORM_LBL_MAP_COLOR" 
onchange="(function(){console.log('onchange triggered')})()"/>

generates the proper:

<input type="text" name="jform[color]" id="jform_color" value="rgba(255, 48, 41, 0.5)" placeholder="Color" class="form-control minicolors rgba minicolors-input valid form-control-success" data-position="default" data-control="hue" onchange="(function(){console.log('onchange triggered')})()" data-format="rgba" size="25" data-opacity="0.50" aria-invalid="false">

In Joomla 5.0.0 Alpha 3

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
3.00

avatar ryanminnig ryanminnig - open - 2 Aug 2023
avatar ryanminnig ryanminnig - change - 2 Aug 2023
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 2 Aug 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 2 Aug 2023
avatar ryanminnig
ryanminnig - comment - 2 Aug 2023

I would be happy to tackle this if someone could point me in towards the correct files. I have very little experience with the core code.


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

avatar chmst
chmst - comment - 4 Aug 2023

"onchange" is not in the atttributes of the color field.
You could write your own color field and extend the Joomla colour field.

avatar ryanminnig
ryanminnig - comment - 4 Aug 2023

Thank you for that clarification. However, according to the CMS documentation found at https://api.joomla.org/cms-4/classes/Joomla-CMS-Form-Field-ColorField.html, onchange is indeed a property. I certainly could be reading this wrong as I've only been developing for Joomla for about 2 years, so I do not have intimate knowledge of the inner workings.

I find it interesting how, apparently with a hack, I was able to achieve the desired results by simply adding more text to the XML field description.


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

avatar Quy
Quy - comment - 4 Aug 2023

This has been fixed in the upcoming v4.3.4 per #41126 and upmerged to v5.0.

avatar Quy Quy - close - 6 Aug 2023
avatar Quy
Quy - comment - 6 Aug 2023

Closing as fixed in the next release.

avatar Quy Quy - change - 6 Aug 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-08-06 04:04:35
Closed_By Quy

Add a Comment

Login with GitHub to post a comment