KyivKrishnaAcademy/ved_akadem_students

View on GitHub
app/assets/javascripts/initTelInput.js.coffee.erb

Summary

Maintainability
Test Coverage
#= require intl-tel-input
#= require intl-tel-input/build/js/utils

window.initTelInput = ->
  telInput = $('#phone:not(.tel-input)')

  telInput.intlTelInput({
    preferredCountries: ['ua', 'by', 'md', 'ru']
    separateDialCode: true
  })

  telInput.on 'keyup change', (e) ->
    $phone = $(e.target)

    $hidden = $phone.closest('.row').find('#hidden-phone')

    $hidden.val($phone.intlTelInput('getNumber'))
    $hidden.attr('name', $phone.attr('name'))

  telInput.addClass('tel-input')