-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Component view is using field clones not a reference. #22115
Comments
I think your code is incorrect. You are modifying the form but the field is already assigned to a variable. So you either need to have two loops, one for modifying the form and one for rendering the fields, or use |
Comment above by @SharkyKZ isn't shown in issue Tracker. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/22115. |
Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/22115 |
@SharkyKZ I know how to make a workaround but its pointless. Objects should be returned as reference. Not a clone. 2 loops requirement is the result of issue, not a cure. Its no critical but its still a bug. |
Ok 1 way of achieve setting the attribute (as mentioned by @SharkyKZ) are $this->form->setFieldAttribute($field->fieldname, 'hint', $field->getAttribute('label'));
echo $this->form->renderField($field->fieldname, $field->group); Another way (instead of str_replace) is to do $field->__set('hint', $field->getAttribute('label'));
echo $field->renderField(); but why some place are using $this->form->renderField('somefieldname'); and other are using why not use everywhere ? $this->form->renderField($field->fieldname, $field->group); |
Steps to reproduce the issue
Create template overrides for
com_contact
.Go to
/templates/yourtheme/com_contact/contact/default_form.php
Try to update field attribute by putting after this:
following code:
Now create new contact and create a new menu item for it.
Go to front end and look at the message form.
Expected result
Each text field should have a
placeholder
attribute same as field label (the code above just uses field label to set text field placeholder).Actual result
Nothing changes.
System information (as much as possible)
Joomla 3.8.12
Additional comments
It looks like on the way to view form fields lose reference. That way it is impossible to update field attributes from inside the view. It leads to dirty workarounds like str_ireplace etc. It worked previously but I'm not sure in which version it started failing. There is still possibility to override form fields layouts for com_contact but that feels like overkill for simple attribute change.
The text was updated successfully, but these errors were encountered: