the function getInputName() on the file administrator\components\com_mycomponent\dom\html\form\input.php
doesn't work properly when the input has formGroups.
Example, let's say we have a fieldname like jform[products][logo]. and we call the function using the suffix variable "current".
it should return: jform[products][logo-current]
but it returns logo-current.
This is a problem when we have various input fields with the same fieldname but different groups.
so the function:
function getInputName($suffix = null)
{
$name = $dataKey = $this->dataKey;
if (!empty($this->formControl))
{
// This feature is not optimized, send 'formControl' only if necessary (when a suffix feature is called)
//Check if formControl is already instancied
if (preg_match("/^" . $this->formControl. "\[(.+)\]$/", $name, $results))
{
//Fin out the dataKey original when formControl is already given in dataKey
if (isset($results[1]))
$dataKey = $results[1];
}
else {
// Embed in the formControl array
$name = "[" . $name . "]";
if (!empty($this->formGroup))
$name = '[' . implode('][', explode('.', $this->formGroup)) . ']' . $name;
$name = $this->formControl . $name;
}
}
//For suffix, must attach it in the group, even when formGroup is not given
if ($suffix)
{
$suffixed = str_replace($dataKey, $dataKey . '-' . $suffix, $name);
return $suffixed;
}
//Return specific value AFTER the prefix step.
if ($this->domName)
return $this->domName;
return $name;
}
should be:
function getInputName($suffix = null)
{
$name = $dataKey = $this->dataKey;
if (!empty($this->formControl))
{
// This feature is not optimized, send 'formControl' only if necessary (when a suffix feature is called)
//Check if formControl is already instancied
if (preg_match("/^" . $this->formControl. "\[(.+)\]$/", $name, $results))
{
//Fin out the dataKey original when formControl is already given in dataKey
if (isset($results[1]))
$dataKey = $results[1];
}
else {
// Embed in the formControl array
$name = "[" . $name . "]";
if (!empty($this->formGroup))
$name = '[' . implode('][', explode('.', $this->formGroup)) . ']' . $name;
$name = $this->formControl . $name;
}
}
//Return specific value AFTER the prefix step.
if ($this->domName)
$name = $this->domName;
//For suffix, must attach it in the group, even when formGroup is not given
if ($suffix)
{
$name = str_replace($dataKey, $dataKey . '-' . $suffix, $name);
}
return $name;
}
also for the function getInputId(), it should be changed to:
function getInputId($suffix = null)
{
$id = $this->dataKey;
if (!empty($this->formControl))
{
if (!empty($this->formGroup))
$id = str_replace('.', '_', $this->formGroup) .'_'. $id;
$id = $this->formControl . '_' . $id;
}
if ($this->domId)
$id = $this->domId;
if ($suffix)
{
$suffixed = $id . '-' . $suffix;
$id = $suffixed;
}
return $id;
}
I let the admin check if these modifications are fit for any situations.