Joomla 字段 : change dynamically the readonly property

标签 joomla joomla2.5

在 Joomla 组件表单中:

有没有办法动态更改表单字段属性:“只读”?

示例:

if( _condition_ )
   $this->form->getInput('Name')->readonly = true;

最佳答案

从我在API中看到的,你基本上可以改变它。

我是这样看的:

当您调用 $this->form->getInput('Name') 时,您位于 JFormField 对象内部(实际上位于一个内部 JFormField 的类中,该类是抽象的 - 例如由 JFormFieldText 继承) ,调用方法getInput()

这个方法,getInput(),从我可以直接看到的获取其参数$element(描述表单字段的XML元素的SimpleXMLElement对象。)您定义的 XML 并且它仅返回一个字符串(实际的 HTML),因此设置和不存在的属性显然不起作用。

但是 JForm 有一个很好的方法,称为 setFieldAttribute(),请参阅下面的签名:

 /**
 * Method to set an attribute value for a field XML element.
 *
 * @param   string  $name       The name of the form field for which to set the attribute value.
 * @param   string  $attribute  The name of the attribute for which to set a value.
 * @param   mixed   $value      The value to set for the attribute.
 * @param   string  $group      The optional dot-separated form group path on which to find the field.
 *
 * @return  boolean  True on success.
 *
 * @since   11.1
 */
public function setFieldAttribute($name, $attribute, $value, $group = null)

所以你的代码可以是这样的:

if( _condition_ ) 
{
    $this->form->setFieldAttribute('Name', 'readonly', 'true', $group = null);
    echo $this->form->getInput('name');
}

希望这有帮助。

关于Joomla 字段 : change dynamically the readonly property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15865597/

相关文章:

joomla - 升级到 Xampp 1.8.1 后,无法查看我的网站

javascript - TinyMCE:添加复杂格式

joomla2.5 - Joomla 2.5 ― 在组件前端使用管理员组件 Controller

php - Joomla:将变量传递给 getInput()

Joomla:博客中的新闻

css - joomla 网站在 firefox 中运行不佳

php - Joomla 3 身份验证以访问 PHP 中的外部应用程序

php - curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$this ,'readHeader' )) 不工作

html - 单元格中的表格图像显示较小

.htaccess - joomla 网站中 Feedburner 的 HTTPS RSS URL 问题