this is wrong:
 <select id="state" name="state">*

*name (and id) should be in AS style, which is very similar (if not same) to
RoR standard format of naming object attributes in a form. Take a look at
finder.rb in AS. It explains in more detail. (PS: i think that should be in
the wiki)
so, you may use name="record_state_id"
*
*besides, you could do everything from
# /views/customers/_state_form_column.html.erb
much less code and simpler in a helper, with something like this:

def state_form_column(record, input_name)
    if not @state.nil?
       select record[:state], @states, :prefix => input_name
    else
       text_field record, :state, { :size=> 30, class=>"state-input
text-input",  :prefix => input_name}
   end
end

the "selected" property is set automagically by RoR's select helper:

http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M001592

now, for the update_states, don't know how to render from a helper, but, how
about taking a look at form_column_chaining?

hope that helps,

On Mon, Jun 15, 2009 at 9:24 AM, JannaB <[email protected]> wrote:

>
> I almost have this perfected for AS, using the Carmen plugin nad
> partial overrides for forms in AS. When someone picks a country, the
> list of possible states to select from appears. If the current
> record's country select box is the same as the record's, it gets that
> record's state selected (if there is one) as well. It works
> marvelously.
>
> The ONLY problem, is that it doesn't update the state when the form
> appears (i.e. in Edit or Create mode). One must first change the
> country selected (then, often, change it back to what it initially
> came up as) to invoke the proper state selections. Can someone please
> tell me from my code below how to accomplish this -- I think this will
> be a nice amendment to this group in case anyone ever does a search on
> country & state. -Janna B.
>
> # /views/customers/_state_form_column.html.erb
> <p>
> <dl class="" id="states">
> <dt>
> <label for="record_state_">State</label>
> </dt>
> <dd>
>  <% if @states !=nil %>
>        <% if @customer!=nil && @customer.state!=nil %>
>                <% s = @customer.state.strip %>
>        <% end %>
>      <select id="state" name="state">
>        <option></option>
>        <% for state in @states %>
>                <option value="<%= state[1] %>"
>                <% if state[1]==s  %>
>                        selected="selected"
>                <% end %>
>                >
>                <%= state[0] %></option>
>        <% end %>
>      </select>
> <% else %>
>        <input type="text" size="30" name="record[state]" maxlength="255"
> id="record_state_" class="state-input text-input" autocomplete="off"/
> >
> <% end %>
> </dd>
> </dl>
>
> # /views/customers/_country_form_column.html.erb
> <p>
> <dl class="">
> <dt>
> <label for="record_country_">Country</label>
> </dt>
> <dd>
>  <% @customer == nil || @customer.country == nil ? s =
> Carmen::country_name(Carmen.default_country) : s =
> @customer.country.strip %>
>   <%= country_select :record, :country, [s], {},
>    {
>      :onChange => remote_function( :url => { :action =>
> 'update_states' }, :update => "states", :with => "'country=' +value")
>    } %>
> </p>
> </dd>
> </dl>
>
> #And finally, my controller:
> class CustomersController < ApplicationController
>
>  active_scaffold :customer do |config|
>       ...
>     end
>
>  ..
>
>   def update_states
>      setstateslist
>      render :partial => 'state_form_column'
>    end
>
>   def setstateslist
>        q = params[:country]
>     if q==nil
>       if params[:id] != nil
>         @customer= Customer.find(params[:id])
>       end
>       if(@customer==nil)
>         q=Carmen.default_country
>       else
>         [email protected]
>       end
>     end
>     if(q!=Carmen.default_country)
>        q1 = q.gsub("_", " ")
>        q.capitalize!
>        if(q1!=q && q1!=nil)
>            q = q1.titleize #q1.split(' ').map {|w| w.capitalize }.join
> (' ')
>        end
>        q = Carmen::country_code(q)
>     end
>    @states =  Carmen::states(q)
>  end
> end
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to