Joomla 2.5在模态窗口中打开视图来添加数据

时间:2013-03-01 06:48:05

标签: view modal-dialog joomla2.5

目标应该是: 我有一个编辑视图,其中包含一个依赖于另一个表的自定义字段(下拉列表)。在那里,我可以从地址列表(第二个表)中进行选择,以保存数据行的ID。我从这开始:

自定义字段代码:

jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
JHTML::_('behavior.modal');
class JFormFieldInvoiceAdress extends JFormFieldList
{
    protected $type = 'invoiceadress';
    protected function getInput() {
        $db = JFactory::getDBO();
        $query = $db->getQuery(true);
        $query->select('id,zip,city,adress');
        $query->from('#__pb_invoiceadresses');
        $db->setQuery((string)$query);
        $types = $db->loadObjectList();
        $options = array();
        foreach($types as $type) {
        $options[] = JHTML::_('select.option', $type->id, $type->zip . " " . $type->city . ", " .$type->adress);
        }
        $dropdown = JHTML::_('select.genericlist', $options, $this->name, 'class="inputbox"', 'value', 'text', $this->value);
        $link = 'index.php?option=com_mycomponent&view=invoiceadresseedit&layout=edit&id=0';
        $dropdown .= "<a href=\"" . JRoute::_($link) . "\" class=\"modal\" rel=\"{handler: 'iframe', size: {x: 875, y: 550}, onClose: function() {}}\" >Neue Adresse</a>";                      
        return $dropdown ;
    }
}

到目前为止这是有效的,但我必须在关闭此模态窗口时更新下拉列表的内容,而不是在模态窗口中获取发票地址的列表视图。

我的第二次尝试是在链接中添加'tmpl = component',但之后我没有保存按钮。我不知道如何做到这一点。有人已经解决了这个问题吗?

1 个答案:

答案 0 :(得分:0)

找到了解决方案,我正在为下一个提出相同问题的人回答这个问题。

使用以下链接调用编辑视图:

$link = 'index.php?option=com_mycomponent&view=invoiceadresseedit&layout=edit&id=0&tmpl=component';

这将只显示没有其他管理gui和工具栏的表单。

在编辑表单中添加一个保存按钮,如下所示:

<input class="button" type="submit" value="<?php echo JText::_('SAVE');?>"  onClick="window.parent.location.reload();" />

就是这样。数据将被保存,然后关闭模态窗口并重新加载当前页面,下拉列表将使用新数据进行更新。