Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline error messages not showing up with Simple Form & Twitter Bootstrap #449

Closed
chrisvfritz opened this issue Dec 18, 2012 · 1 comment

Comments

@chrisvfritz
Copy link

First, thanks for the great gem! There's just one thing that's not working.

For some reason, no error messages are appearing. I've tried the solution from this issue (#286) and even uncommenting the block from the initializer (even though I don't think it should be necessary with simple_form), but nothing so far has worked.

Version of ClientSideValidations (from Gemfile)
gem 'simple_form', '2.0.4'
gem 'client_side_validations', '3.2.1'
gem 'client_side_validations-simple_form', '2.0.1'

Version of Rails (fom Gemfile)
gem 'rails', '3.2.8'

Code snippet from your model of the validations
validates_format_of :url, :with =>
/^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+).[a-z]{2,5}(([0-9]{1,5})?/.)?$/ix, :message => "Invalid URL"
validates_presence_of :title, :url, :message => "Can't be blank"

The form code from your template
<%= simple_form_for @resource, remote: true, :validate => true do |f| %>
<%= f.hidden_field :skill_id, :value => @resource.skill_id %>
<%= f.input :title %>
<%= f.input :url %>
<%= f.association :objectives, :collection => Skill.find("#{@resource.skill_id}").objectives, :as => :check_boxes, :label_method => lambda { |objective| "#{objective.content}" } %>

<%= f.submit %>
<% end %>

The resulting HTML along with the script tag

              <form accept-charset="UTF-8" action="/resources" class="simple_form new_resource" data-remote="true" data-validate="true" id="new_resource" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="CPwGlzgTh29hZfEY2z5/TE+m0oAbqu0IBgRhvHuCxPM=" /></div>

               <input id="resource_skill_id" name="resource[skill_id]" type="hidden" value="1" />
                <div class="control-group string required"><label class="string required control-label" for="resource_title"><abbr title="required">*</abbr> Title</label><div class="controls"><input class="string required" id="resource_title" name="resource[title]" size="50" type="text" /></div></div>
                <div class="control-group url required"><label class="url required control-label" for="resource_url"><abbr title="required">*</abbr> Url</label><div class="controls"><input class="string url required" id="resource_url" name="resource[url]" size="50" type="url" /></div></div>
                <div class="control-group check_boxes optional"><label class="check_boxes optional control-label">Objectives</label><div class="controls"><label class="checkbox"><input class="check_boxes optional" id="resource_objective_ids_1" name="resource[objective_ids][]" type="checkbox" value="1" />Blah</label><label class="checkbox"><input class="check_boxes optional" id="resource_objective_ids_2" name="resource[objective_ids][]" type="checkbox" value="2" />Blah2</label><label class="checkbox"><input class="check_boxes optional" id="resource_objective_ids_3" name="resource[objective_ids][]" type="checkbox" value="3" />Blah3</label><input name="resource[objective_ids][]" type="hidden" value="" /></div></div>
                <div class="actions">
                  <input name="commit" type="submit" value="Create Resource" />
                </div>
</form><script>//<![CDATA[
if(window.ClientSideValidations==undefined)window.ClientSideValidations={};if(window.ClientSideValidations.forms==undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['new_resource'] = {"type":"SimpleForm::FormBuilder","error_class":"help-inline","error_tag":"span","wrapper_error_class":"error","wrapper_tag":"div","wrapper_class":"control-group","wrapper":"bootstrap","validators":{"resource[title]":{"presence":[{"message":"Can't be blank"}]},"resource[url]":{"format":[{"message":"Invalid URL","with":/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/i}],"presence":[{"message":"Can't be blank"}]}}};
//]]></script>
@bcardarella
Copy link
Contributor

Can you please open this up in http://github.com/dockyard/client_side_validations-simple_form

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants