前提・実現したいこと
Select2 Validation エラー時のエラーメッセージの表示位置を変更する方法を教えてください。
ここに質問の内容を詳しく書いてください。
Select2 Validation エラー時のエラーメッセージの表示位置を変更する方法を教えてください。
Ruby on Rails で Select2 を使って、ドロップダウン型の入力フォームを実装しました。
そのフォームに { required: true } を使って、validation を設定し、入力されていない場合は、エラーメッセージが表示されるように実装しました。
現時点では、エラー発生時に、フォームの上にエラーメッセージを含んだタグが生成されますが、フォームの下に生成するように実装したいと考えています。
発生している問題
ローカルで表示した際のコードです。
# エラーメッセージ <p id="prefecture_id-error" class="is-invalid error">都道府県を入力してください</p> # セレクト2 フォーム部分 <span class="select2 select2-container select2-container--default" dir="ltr" data-select2-id="1" style="width: 369.5px;"> <span class="selection"> <span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-disabled="false" aria-labelledby="select2-prefecture_id-container"> <span class="select2-selection__rendered" id="select2-prefecture_id-container" role="textbox" aria-readonly="true" title="未選択"> <span class="select2-selection__clear" title="Remove all items" data-select2-id="3">× </span>未選択 </span> <span class="select2-selection__arrow" role="presentation"> <b role="presentation"></b> </span> </span> </span> <span class="dropdown-wrapper" aria-hidden="true"> </span> </span>
あなたの回答
tips
プレビュー