The FormBuilder helper is called like this:
<% field_validator :object, :name, {options} %>
The options hash is used to specify the different types of validation
for the field (required, numeric, regex, etc). This is where the
problem comes in as well. The helper eventually defers to the
following:
def field_validator_tag(field_id, options={})
# Raise an error if a requested validation type is not
recognized
raise(ArgumentError, "Missing validator options") if
options.empty?
raise(ArgumentError, "Unrecognized validation options.
field_validator recognizes: #{FIELD_VALIDATIONS.join('',
'')}") unless
(options.keys-FIELD_VALIDATIONS).empty?
# Build up a string of the requested validations
options.each do |validation_name, validation_options|
@field_validations.push( _validation_constructor_string_omitted_ );
end
end
The problem is that a side effect of iterating over the options hash
is that the hash elements are emitted and end up on the page in the
place where the field_validator is called. That is, if I have
something like this:
<% validated_form_for :widget, :url=>widgets_path, :method=>:post %>
<p>
<label for="widget_age">Age</label>
<%= f.text_field :age %>
<%= field_validator :widget, :name, :required=>true, :numeric=>true
%>
</p>
...
<% end %>
I end up with rendered markup like this:
<form action="/widgets" id="widget_form"
method="post"
onsubmit="return
Validators.formValidators[''widget_form''].validate_form();">
<p>
<label for="widget_age">Age</label>
<input id="widget_age" name="widget[age]"
size="30" type="text" />
requiredtruenumerictrue
</p>
...
</form>
Any ideas how I can supress the output from the iteration?
(Incidentally, I know that it''s the iteration itself because
I''ve
commented out the single line in the block and still get the keys
rendered in the page).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---