Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow media field to be disabled fully #1151

Merged
merged 1 commit into from

3 participants

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

@mbabker mbabker referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@eddieajau eddieajau merged commit 8ef210c into joomla:staging
@eddieajau

Merged. Thanks.

@benjaminpick benjaminpick referenced this pull request
Merged

Show Media preview #1105

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

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
Commits on Apr 14, 2012
  1. @mbabker
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 20 deletions.
  1. +23 −20 libraries/legacy/form/field/media.php
View
43 libraries/legacy/form/field/media.php
@@ -113,27 +113,30 @@ protected function getInput()
$folder = '';
}
// The button.
- $html[] = '<div class="button2-left">';
- $html[] = ' <div class="blank">';
- $html[] = ' <a class="modal" title="' . JText::_('JLIB_FORM_BUTTON_SELECT') . '"' . ' href="'
- . ($this->element['readonly'] ? ''
- : ($link ? $link
- : 'index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;asset=' . $asset . '&amp;author='
- . $this->form->getValue($authorField)) . '&amp;fieldid=' . $this->id . '&amp;folder=' . $folder) . '"'
- . ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
- $html[] = JText::_('JLIB_FORM_BUTTON_SELECT') . '</a>';
- $html[] = ' </div>';
- $html[] = '</div>';
+ if ($this->element['disabled'] != true)

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
+ {
+ $html[] = '<div class="button2-left">';
+ $html[] = ' <div class="blank">';
+ $html[] = ' <a class="modal" title="' . JText::_('JLIB_FORM_BUTTON_SELECT') . '"' . ' href="'
+ . ($this->element['readonly'] ? ''
+ : ($link ? $link
+ : 'index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;asset=' . $asset . '&amp;author='
+ . $this->form->getValue($authorField)) . '&amp;fieldid=' . $this->id . '&amp;folder=' . $folder) . '"'
+ . ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
+ $html[] = JText::_('JLIB_FORM_BUTTON_SELECT') . '</a>';
+ $html[] = ' </div>';
+ $html[] = '</div>';
- $html[] = '<div class="button2-left">';
- $html[] = ' <div class="blank">';
- $html[] = ' <a title="' . JText::_('JLIB_FORM_BUTTON_CLEAR') . '"' . ' href="#" onclick="';
- $html[] = 'jInsertFieldValue(\'\', \'' . $this->id . '\');';
- $html[] = 'return false;';
- $html[] = '">';
- $html[] = JText::_('JLIB_FORM_BUTTON_CLEAR') . '</a>';
- $html[] = ' </div>';
- $html[] = '</div>';
+ $html[] = '<div class="button2-left">';
+ $html[] = ' <div class="blank">';
+ $html[] = ' <a title="' . JText::_('JLIB_FORM_BUTTON_CLEAR') . '"' . ' href="#" onclick="';
+ $html[] = 'jInsertFieldValue(\'\', \'' . $this->id . '\');';
+ $html[] = 'return false;';
+ $html[] = '">';
+ $html[] = JText::_('JLIB_FORM_BUTTON_CLEAR') . '</a>';
+ $html[] = ' </div>';
+ $html[] = '</div>';
+ }
return implode("\n", $html);
}
Something went wrong with that request. Please try again.