Skip to content
This repository

Allow media field to be disabled fully #1151

Merged
merged 1 commit into from about 2 years ago

3 participants

Michael Babker Andrew Eddie Benjamin Pick
Michael Babker
Owner

In either the form XML or in a model's getForm method (for those extending JModelForm), it is possible to set the disabled attribute on form fields. In trying to use this for some code I'm working on, I've found that in its current form, the media field cannot truly be disabled or read-only. In using $form->setFieldAttribute('logo', 'disabled', 'true'); in my model's getForm method, the Select and Clear buttons are still active and usable. So, for this field to be truly disabled, I've added a check for the disabled element prior to rendering the two buttons.

Use Case:
I'm using the same model in the back end to load a form with one of two layouts: the regular edit layout, and a "details" layout which loads the form data in basically a read-only state and adds a little more data to be viewed by the user.

Michael Babker mbabker referenced this pull request from a commit April 14, 2012
Commit has since been removed from the repository and is no longer available.
Andrew Eddie eddieajau merged commit 8ef210c into from April 16, 2012
Andrew Eddie eddieajau closed this April 16, 2012
Andrew Eddie
Owner

Merged. Thanks.

Benjamin Pick benjaminpick referenced this pull request April 18, 2012
Merged

Show Media preview #1105

Benjamin Pick benjaminpick commented on the diff May 04, 2012
libraries/legacy/form/field/media.php
@@ -113,27 +113,30 @@ protected function getInput()
113 113
 			$folder = '';
114 114
 		}
115 115
 		// The button.
116  
-		$html[] = '<div class="button2-left">';
117  
-		$html[] = '	<div class="blank">';
118  
-		$html[] = '		<a class="modal" title="' . JText::_('JLIB_FORM_BUTTON_SELECT') . '"' . ' href="'
119  
-			. ($this->element['readonly'] ? ''
120  
-			: ($link ? $link
121  
-				: 'index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;asset=' . $asset . '&amp;author='
122  
-				. $this->form->getValue($authorField)) . '&amp;fieldid=' . $this->id . '&amp;folder=' . $folder) . '"'
123  
-			. ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
124  
-		$html[] = JText::_('JLIB_FORM_BUTTON_SELECT') . '</a>';
125  
-		$html[] = '	</div>';
126  
-		$html[] = '</div>';
  116
+		if ($this->element['disabled'] != true)
1
Benjamin Pick
benjaminpick added a note May 04, 2012

This should be != 'true' (XML attribute values are still strings). For testing purposes, use disabled="false" as value - this currently disables the form element as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 14, 2012
Michael Babker Allow media field to be disabled fully 20c4181
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 23 additions and 20 deletions. Show diff stats Hide diff stats

  1. 43  libraries/legacy/form/field/media.php
43  libraries/legacy/form/field/media.php
@@ -113,27 +113,30 @@ protected function getInput()
113 113
 			$folder = '';
114 114
 		}
115 115
 		// The button.
116  
-		$html[] = '<div class="button2-left">';
117  
-		$html[] = '	<div class="blank">';
118  
-		$html[] = '		<a class="modal" title="' . JText::_('JLIB_FORM_BUTTON_SELECT') . '"' . ' href="'
119  
-			. ($this->element['readonly'] ? ''
120  
-			: ($link ? $link
121  
-				: 'index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;asset=' . $asset . '&amp;author='
122  
-				. $this->form->getValue($authorField)) . '&amp;fieldid=' . $this->id . '&amp;folder=' . $folder) . '"'
123  
-			. ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
124  
-		$html[] = JText::_('JLIB_FORM_BUTTON_SELECT') . '</a>';
125  
-		$html[] = '	</div>';
126  
-		$html[] = '</div>';
  116
+		if ($this->element['disabled'] != true)
  117
+		{
  118
+			$html[] = '<div class="button2-left">';
  119
+			$html[] = '	<div class="blank">';
  120
+			$html[] = '		<a class="modal" title="' . JText::_('JLIB_FORM_BUTTON_SELECT') . '"' . ' href="'
  121
+				. ($this->element['readonly'] ? ''
  122
+				: ($link ? $link
  123
+					: 'index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;asset=' . $asset . '&amp;author='
  124
+					. $this->form->getValue($authorField)) . '&amp;fieldid=' . $this->id . '&amp;folder=' . $folder) . '"'
  125
+				. ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
  126
+			$html[] = JText::_('JLIB_FORM_BUTTON_SELECT') . '</a>';
  127
+			$html[] = '	</div>';
  128
+			$html[] = '</div>';
127 129
 
128  
-		$html[] = '<div class="button2-left">';
129  
-		$html[] = '	<div class="blank">';
130  
-		$html[] = '		<a title="' . JText::_('JLIB_FORM_BUTTON_CLEAR') . '"' . ' href="#" onclick="';
131  
-		$html[] = 'jInsertFieldValue(\'\', \'' . $this->id . '\');';
132  
-		$html[] = 'return false;';
133  
-		$html[] = '">';
134  
-		$html[] = JText::_('JLIB_FORM_BUTTON_CLEAR') . '</a>';
135  
-		$html[] = '	</div>';
136  
-		$html[] = '</div>';
  130
+			$html[] = '<div class="button2-left">';
  131
+			$html[] = '	<div class="blank">';
  132
+			$html[] = '		<a title="' . JText::_('JLIB_FORM_BUTTON_CLEAR') . '"' . ' href="#" onclick="';
  133
+			$html[] = 'jInsertFieldValue(\'\', \'' . $this->id . '\');';
  134
+			$html[] = 'return false;';
  135
+			$html[] = '">';
  136
+			$html[] = JText::_('JLIB_FORM_BUTTON_CLEAR') . '</a>';
  137
+			$html[] = '	</div>';
  138
+			$html[] = '</div>';
  139
+		}
137 140
 
138 141
 		return implode("\n", $html);
139 142
 	}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.