Allow jForm to support data attribute#16141
Allow jForm to support data attribute#16141nilesh-more wants to merge 67 commits intojoomla:stagingfrom
Conversation
|
@nilesh-more the output needs to be escaped, e.g. |
|
@DGT41 fixed. Please check once |
| $onchange = !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : ''; | ||
|
|
||
| // Initialize JavaScript field data attributes. For eg, data-action-type="click" | ||
| $dataAttribute = !empty($this->dataAttributeValues) ? ' ' . implode(" ", $this->dataAttributeValues) : ''; |
There was a problem hiding this comment.
Change implode(" ", to implode(' ',.
| break; | ||
|
|
||
| case $this->dataAttributeName = $this->dataAttributeName ? $this->dataAttributeName : '' === $name: | ||
| $this->dataAttributeValues[] = $name . '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; |
There was a problem hiding this comment.
I think this is bad approach,
it does not allow to override value for an existing data- attribute, from outside,
and require of $this->dataAttributeName make it even more unintuitive and complicated.
There was a problem hiding this comment.
here still need a better solution, I think
There was a problem hiding this comment.
@Fedik Please can you elaborate on what you mean by it does not allow to override value for an existing data- attribute, from outside, it will help me to troubleshoot
There was a problem hiding this comment.
Example I have a field:
<field data-blabla="foo" />and at some point of application execution I want to have another value for field data- :
$field->{'data-blabla'} = 'something else';Your current approach does not allow to do this.
There was a problem hiding this comment.
@Fedik, my understanding based on your latest comment is - basically, on the fly you want to change data attribute value
For eg,
-
I have one text field having two data attribute
<form> <fieldset addfieldpath="../../.." name="demo_field"> <field type="text" name="name" data-first-name="Nilesh" data-country="BBB" name="name"/> </fieldset> </form>``` -
Now, suppose you want to change data attribute value form data-country="BBB" to data-country="INDIA" then you can simply use setFieldAttribute($field, $attribute, $value) in your layout file
- for example,
$this->form->setFieldAttribute('text', 'data-country', 'INDIA');
- for example,
-
After execution, output is something like this
<input type="text"
name="jform[name]"
id="jform_name"
data-first-name="Nilesh"
data-country="INDIA" // output - updated value
/>
If you are referring/pointing something different then please explain
There was a problem hiding this comment.
@nilesh-more But would the value need to change from Language to language ? And the problem is that if i was missing those language constants in a different language, would it not break ?
There was a problem hiding this comment.
@nilesh-more no, I meant this:
foreach ($form->getGroup(null) as $field) {
$field->{'data-country'} = 'India';
echo $field->renderField();
}There was a problem hiding this comment.
@Fedik Issue is resolved now.
- Now, you can override value for an existing data-* attribute, from outside by using
- $field->{'data-country'} = 'India'; and - $this->form->setFieldAttribute('text', 'data-country', 'INDIA');
|
any update on this @nilesh-more any additional changes needed on this to merge ? @DGT41 any more fixes needed ? |
|
Sorry din't saw that it where that much files to fix. So here we go. |
|
New tests required. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16141. |
|
@wilsonge can you press the button to update this repo? |
|
I have tested this item ✅ successfully on 64e9d40 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16141. |
1 similar comment
|
I have tested this item ✅ successfully on 64e9d40 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16141. |
|
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16141. |
|
Since this is a new feature it will not go into J3 but I would really like to have this in J4. |
|
@HLeithner is it too much to ask an exception to the rule here from the PLT. Thanks |
|
I'm sorry @dgrammatiko there will be no new features in J3 except they are security related or critical for operation. PLT doesn't changed this for this feature. The focus is clearly on getting Joomla 4.0 released. So it would be great if @nilesh-more can update this PR against J4 or if he is not longer interested someone else can do this. |
|
@dgrammatiko I do not see much sense to push it to j3, now. It is better to concentrate the time and resources on j4. |
|
Please test PR #27212 rebased for J4. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16141. |
Pull Request for Issue #16034
Summary of Changes
HTML5 is designed with extensibility in mind for data that should be associated with a particular element but need not have any defined meaning. data-* attributes allow us to store extra information on the standard, semantic HTML elements without other hacks such as non-standard attributes, extra properties on DOM.
However, custom attributes have no special meaning generally and are only special to the owner's application. They can be used to simplify an application's logic. By allowing JForm to support data attributes, it can be greatly aid development of extensions both core and third party.
Testing Instructions
Add data attribute in XML form, for example
Login into administrator
Click on menu Users => Manage => Add New User
Inspect the filed = Name and check input type html
Expected result
Actual result
Documentation Changes Required