Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] JDOM: functions getInputName and getInputId

JDOM: functions getInputName and getInputId 15 Sep 2013 22:23 #11095

  • Tomaselli
  • Tomaselli's Avatar
  • Offline
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
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.
Last Edit: 17 Sep 2013 23:03 by Tomaselli.
The administrator has disabled public write access.
The following user(s) said Thank You: admin

JDOM: functions getInputName and getInputId 07 Oct 2013 22:59 #11314

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Fixed.
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: Tomaselli

JDOM: functions getInputName and getInputId 08 Oct 2013 07:53 #11325

  • Tomaselli
  • Tomaselli's Avatar
  • Offline
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
thanks :)
The administrator has disabled public write access.
Time to create page: 0.064 seconds

Get Started