カスケード複数選択ドロップダウンメニューで再利用可能なJavaScriptコードを使用しています。使い方の1つでは、完全に動作していますが、まったく同じコードを使用している別の場所では、そうではありません。 何が起こることは、私はなぜそれが働いていない文書(スポット動作していない)とUploadProfiles(workikngスポット)製品に応じて選択しますエージェンシー(IATAs)に割り当てられ、チャネルを作成し、 Symfony Javascriptのドロップダウンが正しく1つの場所で動作しますが、別の場所では正しく動作しません。
を販売していること、である:
- 配列コレクションとしてチャンネルと商品をドキュメントエンティティコンストラクタに追加すると、投稿後に私のドキュメントがチャンネルや製品に割り当てられません。
- 私はコンストラクタからそれらを削除し、私のフォームを送信するとき、私は次のエラーメッセージ
私がコピーしますアレー
上のメンバ関数removeElementへ
()の呼び出しを取得私のエンティティとjavascriptコード。他に何かが必要なら私に知らせてください。他にどこに見えるかわからない。
文書実体
<?php
namespace DocumentBundle\Entity;
use AppBundle\Entity\FileAwareEntity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\Common\Collections\ArrayCollection;
use FS\SolrBundle\Doctrine\Annotation as Solr;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContextInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\Security;
use UserBundle\Entity\User as User;
/**
* @ORM\HasLifecycleCallbacks()
* @ORM\Table(name="document_document", options={"engine"="InnoDB"})
* @ORM\Entity(repositoryClass="DocumentBundle\Entity\DocumentRepository")
*/
class Document extends FileAwareEntity {
/**
* @ORM\Column(type="integer")
* @Solr\Id
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Solr\Field(type="string")
* @Assert\NotBlank()
* @var string
* @ORM\Column(type="string")
*/
private $name;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Agency", inversedBy="documentagencies", cascade={"persist"})
* @ORM\JoinTable(name="document_document_agencies",
* joinColumns={@ORM\JoinColumn(name="document_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="iata8", referencedColumnName="iata8")})
* @var \AppBundle\Entity\Agency
**/
private $agencies;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Market", inversedBy="documents", cascade={"persist"})
* @ORM\JoinTable(name="document_document_markets",
* joinColumns={@ORM\JoinColumn(name="document_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="market_id", referencedColumnName="id")})
* @Assert\Count(
* min = "0"
*)
**/
private $markets;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Airline", inversedBy="documents", cascade={"persist"})
* @ORM\JoinTable(name="document_document_airlines",
* joinColumns={@ORM\JoinColumn(name="document_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="airline_id", referencedColumnName="id")})
* @Assert\Count(
* min = "0"
*)
* @var \AppBundle\Entity\Airline
**/
private $airlines;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Product", inversedBy="documents", cascade={"persist"})
* @ORM\JoinTable(name="document_document_products",
* joinColumns={@ORM\JoinColumn(name="document_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")})
* @Assert\Count(
* min = "0"
*)
* @var \AppBundle\Entity\Product
**/
private $products;
/**
* @ORM\ManyToMany(targetEntity="ReferentialBundle\Entity\Channel1", inversedBy="documents", cascade={"persist"})
* @ORM\JoinTable(name="document_document_channel1",
* joinColumns={@ORM\JoinColumn(name="document_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="channel1_id", referencedColumnName="id")})
* @Assert\Count(
* min = "0"
*)
* @var \ReferentialBundle\Entity\Channel1
**/
private $channel1;
/**
* Constructor
*/
public function __construct()
{
$this->locked = false;
$this->signed = false;
$this->markets = new \Doctrine\Common\Collections\ArrayCollection();
$this->agencies = new \Doctrine\Common\Collections\ArrayCollection();
// $this->channel1 = new \Doctrine\Common\Collections\ArrayCollection();
// $this->products = new \Doctrine\Common\Collections\ArrayCollection();
// $this->airlines = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
function setId($id) {
$this->id = $id;
}
/**
* Set name
*
* @param string $name
* @return Document
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Add agency
*
* @param \AppBundle\Entity\Agency $agency
*
* @return Document
*/
public function addAgency(\AppBundle\Entity\Agency $agency)
{
$this->agencies[] = $agency;
return $this;
}
/**
* Remove agency
*
* @param \AppBundle\Entity\Agency $agency
*/
public function removeAgency(\AppBundle\Entity\Agency $agency)
{
$this->agencies->removeElement($agency);
}
/**
* Get agencies
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAgencies()
{
return $this->agencies;
}
/**
* Add market
*
* @param \AppBundle\Entity\Market $market
*
* @return Document
*/
public function addMarket(\AppBundle\Entity\Market $market)
{
$this->markets[] = $market;
return $this;
}
/**
* Remove market
*
* @param \AppBundle\Entity\Market $market
*/
public function removeMarket(\AppBundle\Entity\Market $market)
{
$this->markets->removeElement($market);
}
/**
* Get markets
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getMarkets()
{
return $this->markets;
}
/**
* Add airline
*
* @param \AppBundle\Entity\Airline $airline
*
* @return Document
*/
public function addAirline(\AppBundle\Entity\Airline $airline)
{
$this->airlines[] = $airline;
return $this;
}
/**
* Remove airline
*
* @param \AppBundle\Entity\Airline $airline
*/
public function removeAirline(\AppBundle\Entity\Airline $airline)
{
$this->airlines->removeElement($airline);
}
/**
* Get airlines
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAirlines()
{
return $this->airlines;
}
/**
* Add product
*
* @param \AppBundle\Entity\Product $product
*
* @return Document
*/
public function addProduct(\AppBundle\Entity\Product $product)
{
$this->products[] = $product;
return $this;
}
/**
* Remove product
*
* @param \AppBundle\Entity\Product $product
*/
public function removeProduct(\AppBundle\Entity\Product $product)
{
$this->products->removeElement($product);
}
/**
* Get products
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProducts()
{
return $this->products;
}
/**
* Add channel1
*
* @param \ReferentialBundle\Entity\Channel1 $channel1
*
* @return Document
*/
public function addChannel1(\ReferentialBundle\Entity\Channel1 $channel1)
{
$this->channel1[] = $channel1;
return $this;
}
/**
* Remove channel1
*
* @param \ReferentialBundle\Entity\Channel1 $channel1
*/
public function removeChannel1(\ReferentialBundle\Entity\Channel1 $channel1)
{
$this->channel1->removeElement($channel1);
}
/**
* Get channel1
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getChannel1()
{
return $this->channel1;
}
}
アップロードプロフィールエンティティ
<?php
namespace DocumentBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
use AppBundle\Entity\Airline;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\ORM\Event\LifeCycleEventArgs;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Entity(repositoryClass="DocumentBundle\Entity\UploadProfileRepository")
* @ORM\Table(name="document_uploadprofile", options={"engine"="InnoDB"})
*/
class UploadProfile{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=100)
*/
private $name;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Market", inversedBy="uploadProfiles", cascade={"persist"})
* @ORM\JoinTable(name="document_uploadprofile_markets",
* joinColumns={@ORM\JoinColumn(name="uploadprofile_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="market_id", referencedColumnName="id")})
**/
private $markets;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Agency", inversedBy="uploadProfiles", cascade={"persist"})
* @ORM\JoinTable(name="document_uploadprofile_agencies",
* joinColumns={@ORM\JoinColumn(name="uploadprofile_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="iata8", referencedColumnName="iata8")})
**/
private $agencies;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Airline", inversedBy="uploadProfiles", cascade={"persist"})
* @ORM\JoinTable(name="document_uploadprofile_airlines",
* joinColumns={@ORM\JoinColumn(name="uploadprofile_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="airline_id", referencedColumnName="id")})
* @var \AppBundle\Entity\Airline
**/
private $airlines;
/**
* @ORM\ManyToMany(targetEntity="ReferentialBundle\Entity\Channel1", inversedBy="uploadProfiles", cascade={"persist"})
* @ORM\JoinTable(name="document_uploadprofile_channel1",
* joinColumns={@ORM\JoinColumn(name="uploadprofile_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="channel1_id", referencedColumnName="id")})
* @var \ReferentialBundle\Entity\Channel1
**/
private $channel1;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Product", inversedBy="uploadProfiles", cascade={"persist"})
* @ORM\JoinTable(name="document_uploadprofile_products",
* joinColumns={@ORM\JoinColumn(name="uploadprofile_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")})
* @Assert\Count(
* min = "1"
*)
* @var \AppBundle\Entity\Product
**/
private $products;
/**
* Constructor
*/
public function __construct()
{
$this->agencies = new \Doctrine\Common\Collections\ArrayCollection();
$this->markets = new \Doctrine\Common\Collections\ArrayCollection();
// $this->channel1s = new \Doctrine\Common\Collections\ArrayCollection();
// $this->channel3s = new \Doctrine\Common\Collections\ArrayCollection();
$this->locked = false;
$this->archived = false;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
function setId($id) {
$this->id = $id;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set name
*
* @param string $name
* @return UploadProfile
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Add market
*
* @param \AppBundle\Entity\Market $market
*
* @return UploadProfile
*/
public function addMarket(\AppBundle\Entity\Market $market)
{
$this->markets[] = $market;
return $this;
}
/**
* Remove market
*
* @param \AppBundle\Entity\Market $market
*/
public function removeMarket(\AppBundle\Entity\Market $market)
{
$this->markets->removeElement($market);
}
/**
* Get markets
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getMarkets()
{
return $this->markets;
}
/**
* Add agency
*
* @param \AppBundle\Entity\Agency $agency
*
* @return UploadProfile
*/
public function addAgency(\AppBundle\Entity\Agency $agency)
{
$this->agencies[] = $agency;
return $this;
}
/**
* Remove agency
*
* @param \AppBundle\Entity\Agency $agency
*/
public function removeAgency(\AppBundle\Entity\Agency $agency)
{
$this->agencies->removeElement($agency);
}
/**
* Get agencies
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAgencies()
{
return $this->agencies;
}
/**
* Add airline
*
* @param \AppBundle\Entity\Airline $airline
*
* @return UploadProfile
*/
public function addAirline(\AppBundle\Entity\Airline $airline)
{
$this->airlines[] = $airline;
return $this;
}
/**
* Remove airline
*
* @param \AppBundle\Entity\Airline $airline
*/
public function removeAirline(\AppBundle\Entity\Airline $airline)
{
$this->airlines->removeElement($airline);
}
/**
* Get airlines
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAirlines()
{
return $this->airlines;
}
/**
* Add channel1
*
* @param \ReferentialBundle\Entity\Channel1 $channel1
*
* @return UploadProfile
*/
public function addChannel1(\ReferentialBundle\Entity\Channel1 $channel1)
{
$this->channel1[] = $channel1;
return $this;
}
/**
* Remove channel1
*
* @param \ReferentialBundle\Entity\Channel1 $channel1
*/
public function removeChannel1(\ReferentialBundle\Entity\Channel1 $channel1)
{
$this->channel1->removeElement($channel1);
}
/**
* Get channel1
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getChannel1()
{
return $this->channel1;
}
/**
* Add product
*
* @param \AppBundle\Entity\Product $product
*
* @return UploadProfile
*/
public function addProduct(\AppBundle\Entity\Product $product)
{
$this->products[] = $product;
return $this;
}
/**
* Remove product
*
* @param \AppBundle\Entity\Product $product
*/
public function removeProduct(\AppBundle\Entity\Product $product)
{
$this->products->removeElement($product);
}
/**
* Get products
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProducts()
{
return $this->products;
}
}
私のJavaScript関数(それが1だので、私は、エラーがそこにあるということを信じることができないにもかかわらず:両方のために同じコード1
<script type="text/javascript">
var message = false;
// Form dropdown disabling
$(document).ready(function(){
// disable channel, product, agency
init_MCPA_DDs();
document.getElementById("___before-submit___").disabled = true;
});
$('#helpModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
header = button.data('header') // Extract info from data-* attributes
text = button.data('text')
var modal = $(this)
modal.find('.modal-title').text(header)
modal.find('.modal-body').text(text)
});
// Market->Channel1->Product->Agency Selection
function init_MCPA_DDs()
{
$('#{{ form.vars.name }}_channel1').multiselect('disable');
$('#{{ form.vars.name }}_products').multiselect('disable');
$('#{{ form.vars.name }}_agencies').multiselect('disable');
//
$('#{{ form.vars.name }}_markets').on("change",function() {
if($(this).val() != null) {
$('#{{ form.vars.name }}_channel1').multiselect('enable');
}
});
}
function refresh_all_ms()
{
// BS MS SA Fix
$('#{{ form.vars.name }}_markets').multiselect('refresh');
$('#{{ form.vars.name }}_channel1').multiselect('refresh');
$('#{{ form.vars.name }}_products').multiselect('refresh');
$('#{{ form.vars.name }}_agencies').multiselect('refresh');
}
function reset_P()
{
$('#{{ form.vars.name }}_products').empty();
$('#{{ form.vars.name }}_products').multiselect('rebuild');
$('#{{ form.vars.name }}_products').multiselect('disable');
}
function reset_A()
{
$('#{{ form.vars.name }}_agencies').empty();
$('#{{ form.vars.name }}_agencies').multiselect('rebuild');
$('#{{ form.vars.name }}_agencies').multiselect('disable');
document.getElementById("___before-submit___").disabled = true;
}
function reset_PA()
{
reset_P();
reset_A();
}
var market_data = new String('___');
var channel1_data = new String('____');
var product_data = new String('____');
makeMultiselectDropdown('#{{ form.vars.name }}_airlines', 'Select Airlines');
makeMultiselectDropdown('#{{ form.vars.name }}_markets', 'Select Markets', {
onDropdownShown: function(event) {
market_data = $('#{{ form.vars.name }}_markets').val();
if (market_data == null) { market_data = '___'; }
},
onDropdownHide: function(event) {
var md = $('#{{ form.vars.name }}_markets').val();
if (md == null) {
md = '____';
reset_PA();
}
if (market_data.toString().localeCompare(md)) {
reset_PA();
handleMarketChannelChoice(true);
}
refresh_all_ms();
}
});
makeMultiselectDropdown('#{{ form.vars.name }}_channel1', 'Select Channel', {
onDropdownShown: function(event) {
channel1_data = $('#{{ form.vars.name }}_channel1').val();
if (channel1_data == null) { channel1_data = '____'; }
},
onDropdownHide: function(event) {
var cd = $('#{{ form.vars.name }}_channel1').val();
if (cd == null) {
cd = '____';
reset_PA();
}
if (channel1_data.toString().localeCompare(cd)) {
reset_PA();
handleMarketChannelChoice(true);
}
refresh_all_ms();
}
});
makeMultiselectDropdown('#{{ form.vars.name }}_products', 'Select Products', {
onDropdownShown: function(event) {
product_data = $('#{{ form.vars.name }}_products').val();
if (product_data == null) { product_data = '___'; }
},
onDropdownHide: function(event) {
var pd = $('#{{ form.vars.name }}_products').val();
if (pd == null) {
pd = '____';
reset_A();
}
if (product_data.toString().localeCompare(pd)) {
reset_A();
handleProductChoice(true);
}
refresh_all_ms();
}
});
makeMultiselectDropdown('#{{ form.vars.name }}_agencies', 'Select Agencies', {
onDropdownHide: function(event) {
refresh_all_ms();
},
onDropdownHide: function(event) {
var ad = $('#{{ form.vars.name }}_agencies').val();
if (ad !== null && ad !=='text') {
document.getElementById("___before-submit___").disabled = false;
}
}
});
//Populate Product dropdown
function handleMarketChannelChoice() {
var channel1 = $('#{{ form.vars.name }}_channel1').val();
var market = $('#{{ form.vars.name }}_markets').val();
if (market === null || channel1 === null) return false;
path = "{{ path('documentBundle_marketChannelData') }}";
$.get(path,
{market: market, channel1: channel1},
function(response) {
response = JSON.parse(response);
if(response.code == '100' && response.success) {
$('#{{ form.vars.name }}_products').empty();
for (var i=0; i<response.productName.length; i++) {
$('#{{ form.vars.name }}_products').append($('<option>', {
value: response.productId[i],
text: response.productName[i]
}));
}
$('#{{ form.vars.name }}_products').multiselect('rebuild');
$('#{{ form.vars.name }}_products').multiselect('enable');
} else {
alert('No Products found for selected Market, Channel');
}
}
);
}
//Populate Agency Dropdown
function handleProductChoice() {
var product = $('#{{ form.vars.name }}_products').val();
if (product === null) return false;
path = "{{ path('documentBundle_productData') }}";
$.get(path,
{product: product,},
function(response) {
response = JSON.parse(response);
if(response.code == '100' && response.success) {
$('#{{ form.vars.name }}_agencies').empty();
for (var i=0; i<response.agencyId.length; i++){
$('#{{ form.vars.name }}_agencies').append($('<option>', {
value: response.agencyId[i],
text: response.agencyName[i]
}));
}
$('#{{ form.vars.name }}_agencies').multiselect('rebuild');
$('#{{ form.vars.name }}_agencies').multiselect('enable');
} else {
alert('No Agencies found for selected Market, Channel, Product');
}
}
);
}
</script>
アップロードプロファイルの場合、javascriptとフォームの種類は同じtwigのテンプレートに含まれています食べて、他のJavaScriptにアクセスしていない。 もう少し複雑です:
他のtwigテンプレートにあるドキュメント作成用のフォームタイプを含むcreate-twig-templateがあります。 create-twig-templateとform-twig-templateの両方に、javascriptファイルと2つのjavascriptファイルが含まれています。 この情報が必要かどうかわかりませんが、私はあなたに状況を知らせると思っていました。
ありがとうございます!
SPAとは何ですか、あなたはどのIDについて話していますか?異なるフォームタイプであるため、関数はすべて一斉に実行されます。 – sonja
idグローバル属性は、ドキュメント全体で一意でなければならない一意の識別子(ID)を定義します。その目的は、(フラグメント識別子を使用して)リンクするとき、スクリプティングするとき、または(CSSを用いて)スタイリングするときに要素を識別することである。 [link](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id) – jriver27
私はIDが何であるか知っています。私のIDはすべてユニークです。私はちょうどあなたの答えが私の問題を解決するのに役立つはずです理解していません 私の機能はすべて正しく発射されます。ドロップダウン自体は正しいデータで作業するために働いています。 – sonja