0

Zend Framework 2 を使用して、フォーム オブジェクトに複数選択ボックスを作成しました。

$contacts = new Element\Select('contacts');
$contacts->setLabel('All Contacts')
         ->setAttribute('name', 'contacts')
         ->setAttribute('multiple', 'multiple')
         ->setAttribute('size', 10)
         ->setOptions(array('options' => $users));

フォームのボタンが押されたときにいくつかの JavaScript を実行したいと思います。

$moveAllRight = new Element\Button('moveAllRight');
$moveAllRight->setLabel('Move All ->')
         ->setAttribute('value', 'Move All ->')
         ->setAttribute('onClick', 'moveAll(this.form.contacts,this.form.newContacts)');

残念ながら、ページが作成されると、複数選択要素の名前に [] が追加されます。

<select name="contacts[]" multiple="multiple" size="10">

私はjs関数呼び出し内の名前を変更しようとしました:

->setAttribute('onClick', 'moveAll(this.form.contacts[],this.form.newContacts[])');

しかし、私はまだそれを機能させることができません。選択ボックスから複数のオプションを削除すると機能しますが、可能であれば複数の選択ボックスを使用したいと思います。とにかくこれを機能させる方法はありますか?

4

1 に答える 1

0

form要素もidで参照できることに気付きました。使用しようとしていた名前と同じ値で id 属性を設定しました。

$contacts = new Element\Select('contacts');
$contacts->setLabel('All Contacts')
         ->setAttribute('id', 'contacts')
         ->setAttribute('multiple', 'multiple')
         ->setAttribute('size', 10)
         ->setOptions(array('options' => $users));

要素がページに作成されます。

<select name="contacts[]" id="contacts" multiple="multiple" size="10">

そして、私が最初に望んでいたように、それを参照できるようになりました:

->setAttribute('onClick', 'moveAll(this.form.contacts,this.form.newContacts)');
于 2013-08-01T19:16:23.720 に答える