Last active
December 4, 2018 04:34
-
-
Save abhianair/6a3389bd2b0f76b832ae70e69f1c5627 to your computer and use it in GitHub Desktop.
Update Country code field upon selecting Country field using AJAX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
$("#id_country_code").change(function(){ | |
var option = $(this).val(); | |
$.ajax({ | |
type: "GET", | |
url: "/models/get", | |
data:{ | |
key: option | |
}, | |
success: function(response){ | |
if(response.phone) | |
$("#phone").val(response.phone); | |
} | |
}) | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@c = params[:key] | |
@c = ISO3166::Country.new(@c) | |
@c = @c.country_code | |
@c = "+#{@c}" | |
render json: {:phone => @c} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources :models do | |
collection do | |
get 'get' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment