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="(function(){console.log('change')})()""/>
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">
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
Joomla 4.3.3 (also the same behavior on Joomla 4.2.2)
<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
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
"onchange" is not in the atttributes of the color field.
You could write your own color field and extend the Joomla colour field.
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.
Closing as fixed in the next release.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-08-06 04:04:35 |
Closed_By | ⇒ | Quy |
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.