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