使用Extbase/Fluid TYPO3中的Javascript向ObjectStorage添加/创建元素 [英] Add/Create Element to ObjectStorage using Javascript in Extbase/Fluid TYPO3

查看:59
本文介绍了使用Extbase/Fluid TYPO3中的Javascript向ObjectStorage添加/创建元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JavaScript动态地在Fluid Form中动态创建新的子元素的正确方法是什么?

what is the correct way to dynamically create new Child Elements in a Fluid Form using JavaScript?

问题: 使用Extbase ObjectStorages的1:n关系(父/子): 当调用父流体形式"时,应该可以添加多个子流体(当然包括属性!)

Problem: 1:n Relation (Parent/Child) using Extbase ObjectStorages: When the Parent Fluid Form is called it should be possible to add several childs (incl. properties of course!)

肮脏,部分正常工作,解决方案: 我添加了一些JS代码,并动态添加了所需的输入元素. 每个孩子都将插入"xxx".数据将正确存储在数据库中.

Dirty, partly working, Solution: I added some JS Code and added the required input elements dynamically. The "xxx" will be interated for each Child. The data will be correctly stored in the DB.

<input type="text" placeholder="First Name" name="tx_booking[newBooking][accompanyingperson][xxx][firstname]">

但是,如果发生错误,则所有子窗体都将消失,并且不会显示f3窗体错误.造成这种情况的原因可能是重定向到originalRequest(没有子字段的初始形式).

However, if an error occurres all child forms disappear and no f3-form-error will be shown. The reason for this, may be the redirect to originalRequest (initial form without child fields).

如何在没有肮脏技巧的情况下处理此问题? 请给我衬衫的提示.

How can I handle this Problem without dirty tricks? Please give me shirt hint.

推荐答案

同样,我会亲自回答问题! 以下几行是有史以来最糟糕的代码,但它可以工作. 我真的很想知道如何以正确的方式做到这一点.但是,解决方案是从动态添加的JS输入中获取参数.这是在errorAction中完成的,并且将由forward()传递给应在其中出现错误的初始Action.

Again, I will answer the question myself! The following lines are the foulest code ever but it works. I really want to know how to do this in a correct way. However, the solution is, to get the Arguments from the dynamically added JS Inputs. This is done in the errorAction and will be passed by the forward() to the initial Action, where the Errors should be appear.

我所有人都认为,那一定是使用PropertyMapper并修改trustedProperties的更好方法.

I for all think, that must be a better way by using the PropertyMapper and modify the trustedProperties....

这是一个简短的示例:

    // Error function in Controller

protected function errorAction() {

    $referringRequest = $this->request->getReferringRequest();

    // Manual added JS Data
    if($this->request->hasArgument('newRegistration'))
    {
        $newRegistration = $this->request->getArgument('newRegistration');
        $referringRequest->setArgument('accompanyingperson', $newRegistration['accompanyingperson']);
    }

     if ($referringRequest !== NULL) {
        $originalRequest = clone $this->request;
        $this->request->setOriginalRequest($originalRequest);
        $this->request->setOriginalRequestMappingResults($this->arguments->getValidationResults());
        $this->forward($referringRequest->getControllerActionName(), $referringRequest->getControllerName(), $referringRequest->getControllerExtensionName(), $referringRequest->getArguments());

    }
}


// action new in Controller
public function newAction(\***\***\Domain\Model\Registration $newRegistration = NULL) {
    if($this->request->hasArgument('accompanyingperson'))
    {
        $this->view->assign('accPer', $this->request->getArgument('accompanyingperson'));
    }
    .
    .
    .
}


//Fluid template of Action New
<f:if condition="{accPer}">
    <f:for each="{accPer}" as="ap" key="key" iteration="i">
        <f:form.textfield class="form-control" placeholder="First Name" property="accompanyingperson.{key}.firstname"/>
        .
        .
        .
    </f:for>
</f:if>

这篇关于使用Extbase/Fluid TYPO3中的Javascript向ObjectStorage添加/创建元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆