2017-02-23 14 views
0

ではありませんが、私はフィールドタイプのエンティティとのために持って、選択肢をドロップダウンしてフォームを送信するとき、真の必要なく、別のフィールドの検証コンソールにsymfonyのフォームは、「フォーカス可能

An invalid form control with name='inbound_invoice_row[costObject]' is not focusable. 
new:1 An invalid form control with name='inbound_invoice_row[accountingAccount]' is not focusable. 
new:1 An invalid form control with name='inbound_invoice_row[user]' is not focusable. 

をエラーが発生しているの」name =に無効なフォームコントロールを検証しますコンソール でこのエラーを持っているバットや価格のようなもののaccountingAccountユーザーcostObjectの罰金、なぜ私のフォーム

理解

/** 
* @param FormBuilderInterface $builder 
* @param array $options 
*/ 
public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    $builder 
     ->add('location', EntityType::class, [ 
      'class' => Location::class, 
      'empty_value' => 'select_default_value', 
      'query_builder' => self::getLocations(), 
      'required' => false, 
      'label' => 'locations', 
      'translation_domain' => 'invoicing' 
     ]) 
     ->add('costObject', EntityType::class, [ 
      'class' => CostObject::class, 
      'empty_value' => 'select_default_value', 
      'choices' => self::getCostObjectHierarchy(), 
      'required' => true, 
      'label' => 'cost_object', 
      'translation_domain' => 'invoicing' 
     ]) 
     ->add('accountingAccount', EntityType::class, [ 
      'class' => AccountingAccount::class, 
      'empty_value' => 'select_default_value', 
      'query_builder' => self::getAccountingAccount(), 
      'required' => true, 
      'label' => 'accounting_account', 
      'translation_domain' => 'invoicing' 
     ]) 
     ->add('user', EntityType::class, [ 
      'class' => User::class, 
      'empty_value' => 'select_default_value', 
      'choices' => self::getR(), 
      'required' => true, 
      'label' => 'employee', 
      'translation_domain' => 'invoicing' 
     ]) 
     ->add('description', TextType::class, [ 
      'label' => 'description', 
      'required' => false, 
      'translation_domain' => 'invoicing' 
     ]) 
     ->add('vat', ChoiceType::class, [ 
      'choices' => $this->vatClasses, 
      'required' => true, 
      'label' => 'vat', 
      'translation_domain' => 'common' 
     ]) 
     ->add('price', TextType::class, [ 
      'label' => 'price', 
      'required' => true, 
      'translation_domain' => 'invoicing' 
     ]); 
} 
/** 
* @param OptionsResolver $resolver 
*/ 
public function configureOptions(OptionsResolver $resolver) 
{ 
    $resolver->setDefaults(array(
     'data_class' => 'EconomyBundle\Entity\InboundInvoiceRow', 
     'locations' => [], 
     'employees' => [], 
     'accounts' => [], 
     'vat' => [], 
     'cost' => [], 
     'ajax' => true, 
     'csrf_protection' => true 
    )); 
} 
public function getName() 
{ 
    return 'inbound_invoice_row'; 
} 

フォームを実際に作成する

答えて

1

おそらく、これらのフィールドをレンダリングするときに使用するjsライブラリがあります。 Select2またはChosen)。フィールドにいくつかのHTML検証エラー(フィールドは必要ですが値はありません)が表示されていませんが、表示されません。displayプロパティがnoneに設定されている場合、ブラウザはそのフィールドにエラーメッセージを添付できません。これがあなたのエラーを引き起こす可能性が最も高いものです。

最も簡単な解決策は、フォームタイプオプションに'required' => falseを設定し、基本的なHTML検証ではなく、バックエンド検証(例えば、Symfony検証コンポーネントを使用)に依存することです。

関連する問題