I have an API that requires several callouts based on the option the user chooses.
To start with I call out to get a list of countries - then based on the choice of countries I need to call out for states (which seems a standard sort of process). But I am having difficulty (or rather cannot) get an onchange action to happen.
My select option is defined as:
def country_selection_input options = {}
options.reverse_merge!(
:attribute => :country_iso,
:collection => transaction_form.get_countries()[:Countries],
:label_method => :Name,
:value_method => :IsoCode,
:input_html => {},
:onchange => 'get_states',
:remote => 'true',
:prompt => 'please select',
:label => 'To Where'
)
call_input_from_args_hash options
end
I have tried doing a simple change action:
$("#transaction_country_iso").change ( function () {
alert('clicked');
});
I get nothing - no action.
I have defined a function in application.js:
function get_states {
$('#transaction_country_iso').change(function(){
alert('clicked');
});
and get
ReferenceError: get_states is not defined
I seem to be following the suggestions I have found here - but - sadly nothing seems to work for me. This seems to be such a standard thing to do that finding a how to is impossible. the remote_function option - which seemed to be the answer- no longer works. I would seem to need to use Jquery - but specifically how to do that is eluding me. I believe need to do some sort of routing action if I want to get to a controller - but as the initial action of getting the onchange to do anything is not working- I am taking it one step at a time. If you can address the get to the controller action step as well in your answer that would be extremely good.
Aucun commentaire:
Enregistrer un commentaire