Hi Matt,
I haven''t used the :function option before. I find it easier just to
write the JS when I want to keep it all in the browser, so take what
follows with a grain of salt.
On Thu, 2009-06-25 at 19:10 +0200, Matt Young wrote:> Bill,
> I have a collection select that shows a list of users:
> <%= collection_select(:person, :convert, @nonUsers, :id, :fullName,
> {:prompt => "Choose..."}, :style =>
"width:125px;") %>
>
> And a text field:
> <%= text_field_tag :userName %>
>
> When a user is selected I''m trying to pull that user out of a
array
> variable that I already have set up, @nonUsers (used to populate the
> collection_select), and have that user''s userName put into the
text box.
That''s not what you want to do. observe_field will capture / pass
selected value.
> I can''t seem to figure out how to access the value of
what''s been
> selected with an observe_field.
>
> (Trying to do all this with RJS and not make a post back to the server).
Personally, I''d do it against the server first (because it''s
oh-so-simple) and leave the optimization until performance is an issue.
> My observe_field looks like:
> <%= observe_field "person_convert", :function =>
update_page {|page|
> page["userName"].value = @nonUsers.select{|p| p.id == *****
}.collect{
> |p| p.fullName } }%>
> BUT I''m not sure what to put in place of the ***** to get that
> collection_select''s selected value.
If I''m reading the api / code for observe_field right, I''m not
sure
the :function variation supports what you want to do. As best I can
tell (having not much time to review the Rails source), if it does, the
final form would, I think, look something like this:
<%= observe_field("person_convert", :function =>
"update_page(*****)"}%>
But in the build_observer source, it doesn''t look like there''s
a way to
pass the value in. Looks like it''s just passing the
"update_page(*****)" without any further processing.
I know that''s not much help. Sorry. My recommendation would be to
repost your problem under a more descriptive Subject line. Something
like ''problem passing selected value to observe_field
:function''
Best regards,
Bill