Monday, 9 January 2017

Jquery Validation dan Select2 : An invalid form control with name='' is not focusable.

Lihat juga : JQuery : Client Side Validation

Ketika menggunakan Select2 [1] dengan jQuery Validation [2] saya menemukan error :

" An invalid form control with name='' is not focusable."

Setelah googling sebentar saya menemukan jawabannya di [3][4].

Solusinya :

Tambahkan CSS berikut :

.select2-wrapper {
    display: inline-block;
    position: relative;
}

Kemudian ketika inisiasi select2, tambahkan attr seperti berikut :

  $("#selector").select2({
              placeholder: "Pilih",
              allowClear: false
  }).attr('style','display:block; position:absolute; bottom: 0; left: 0; clip:rect(0,0,0,0);');


Referensi


  1. Select2, The jQuery replacement for select boxes, https://select2.github.io/
  2. jQuery Validation Plugin, https://jqueryvalidation.org/
  3. How to use with a form validator? #584, https://github.com/select2/select2/issues/584
  4. fiddle How to use with a form validator, http://jsfiddle.net/q7kxsf17/10/

No comments:

Post a Comment