J3 Issue ?
avatar artur-stepien
artur-stepien
10 Sep 2018

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:

<?php foreach ($fields as $field) : ?>

following code:

/* @var $field FormField */
$name = $field->getAttribute('name');
$this->form->setFieldAttribute($name, 'hint', $field->getAttribute('label'));

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.

avatar artur-stepien artur-stepien - open - 10 Sep 2018
avatar joomla-cms-bot joomla-cms-bot - labeled - 10 Sep 2018
avatar franz-wohlkoenig franz-wohlkoenig - change - 11 Sep 2018
Status New Discussion
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 11 Sep 2018

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.

avatar brianteeman brianteeman - change - 30 Oct 2018
Labels Added: J3 Issue
avatar brianteeman brianteeman - labeled - 30 Oct 2018
avatar Quy Quy - change - 29 Dec 2018
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2018-12-29 03:28:26
Closed_By Quy
avatar joomla-cms-bot joomla-cms-bot - change - 29 Dec 2018
Closed_Date 2018-12-29 03:28:26 2018-12-29 03:28:27
Closed_By Quy joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 29 Dec 2018
avatar joomla-cms-bot
joomla-cms-bot - comment - 29 Dec 2018

Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/22115

avatar artur-stepien
artur-stepien - comment - 29 Dec 2018

@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.

avatar ggppdk
ggppdk - comment - 29 Dec 2018

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
$field->renderField() ?

why not use everywhere ?

$this->form->renderField($field->fieldname, $field->group);

Add a Comment

Login with GitHub to post a comment