error messages not appearing #444

Closed
ctuna opened this Issue Nov 30, 2012 · 12 comments

Comments

Projects
None yet
2 participants

ctuna commented Nov 30, 2012

I followed the guide in the README, update the initializer, installed the gem, etc, but when I insert blank/bad data, nothing happens.
also, when I inspect the page, the html does not appear to be doing anything new:

  < script src="/assets/prototype.js" type="text/javascript"></script>
  < script src="/assets/rails.validations.js?body=1" type="text/javascript"></script>
  < form accept-charset="UTF-8" action="/submitters" class="new_submitter" id="new_submitter" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="UJFt3uZ7AekTOTNqXti2zs/CIlMS1Hs7qYWrSTqSu7U=" /></div>
    full name:
    < input id="submitter_full_name" name="submitter[full_name]" size="30" type="text" />
    < br>
    email address:
    < input id="submitter_email_address" name="submitter[email_address]" size="30" type="email" />
    < input name="commit" type="submit" value="Create" />
  < /form>
Contributor

bcardarella commented Nov 30, 2012

Can you give me the full HTML from the page?

ctuna commented Nov 30, 2012

Sure thing! And thank you for your prompt reply.

here is the html outputted:

<html>
  <head>
    <form accept-charset="UTF-8" action="/submissions/search" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="UJFt3uZ7AekTOTNqXti2zs/CIlMS1Hs7qYWrSTqSu7U=" /></div>
        <input id="id" name="id" type="text" />
        <input name="commit" type="submit" value="jump to" />
    </form>
  </head>
  <body>
    <b>New Submission</b>
<br>
<form accept-charset="UTF-8" action="/submitters" class="new_submitter" data-validate="true" id="new_submitter" 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="UJFt3uZ7AekTOTNqXti2zs/CIlMS1Hs7qYWrSTqSu7U=" /></div>
  full name:
  <input id="submitter_full_name" name="submitter[full_name]" size="30" type="text" />
  <br>
  email address:
  <input id="submitter_email_address" name="submitter[email_address]" size="30" type="email" />
  <input name="commit" type="submit" value="Create" />
</form>
<script>//<![CDATA[
if(window.ClientSideValidations==undefined)window.ClientSideValidations={};if(window.ClientSideValidations.forms==undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['new_submitter'] = {"type":"ActionView::Helpers::FormBuilder","input_tag":"<div class=\"field_with_errors\"><span id=\"input_tag\" /><label for=\"\" class=\"message\"></label></div>","label_tag":"<div class=\"field_with_errors\"><label id=\"label_tag\" /></div>","validators":{"submitter[full_name]":{"presence":[{"message":"can't be blank"}]},"submitter[email_address]":{"presence":[{"message":"can't be blank"}],"uniqueness":[{"message":"this email is already in use.","case_sensitive":false}]}}};
//]]></script>
  </body>
</html>
Contributor

bcardarella commented Nov 30, 2012

Did you generate the initializer and uncomment the code in it?

ctuna commented Nov 30, 2012

Yes. Here is the code in client_side_validations.rb

    # ClientSideValidations Initializer

    # Uncomment to disable uniqueness validator, possible security issue
    # ClientSideValidations::Config.disabled_validators = [:uniqueness]

    # Uncomment the following block if you want each input field to have the validation messages attached.
     ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
       unless html_tag =~ /^<label/
         %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}\
    .html_safe
       else
         %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
      end
     end
Contributor

bcardarella commented Dec 1, 2012

Something is not right, the HTML you gave me looks incomplete. Did you change it in any way before pasting?

ctuna commented Dec 1, 2012

I put some spaces in the tags to escape the html before. I have repasted it again without those spaces. I haven't modified anything. What is missing?

Contributor

bcardarella commented Dec 1, 2012

I don't see any jquery or rails.validations.js being included anywhere. The <head> is incorrect.

ctuna commented Dec 1, 2012

Oh! Right! I had those include statements before, but removed them for some reason. I've put them back. Here is the new html

<html>
  <head>
    <form accept-charset="UTF-8" action="/submissions/search" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="UJFt3uZ7AekTOTNqXti2zs/CIlMS1Hs7qYWrSTqSu7U=" /></div>
        <input id="id" name="id" type="text" />
        <input name="commit" type="submit" value="jump to" />
    </form>
    <script src="/assets/prototype.js?body=1" type="text/javascript"></script>
    <script src="/assets/rails.validations.js?body=1" type="text/javascript"></script>
  </head>
  <body>
    <b>New Submission</b>
<br>
<form accept-charset="UTF-8" action="/submitters" class="new_submitter" data-validate="true" id="new_submitter" 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="UJFt3uZ7AekTOTNqXti2zs/CIlMS1Hs7qYWrSTqSu7U=" /></div>
  full name:
  <input id="submitter_full_name" name="submitter[full_name]" size="30" type="text" />
  <br>
  email address:
  <input id="submitter_email_address" name="submitter[email_address]" size="30" type="email" />
  <input name="commit" type="submit" value="Create" />
</form>
<script>//<![CDATA[
if(window.ClientSideValidations==undefined)window.ClientSideValidations={};if(window.ClientSideValidations.forms==undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['new_submitter'] = {"type":"ActionView::Helpers::FormBuilder","input_tag":"<div class=\"field_with_errors\"><span id=\"input_tag\" /><label for=\"\" class=\"message\"></label></div>","label_tag":"<div class=\"field_with_errors\"><label id=\"label_tag\" /></div>","validators":{"submitter[full_name]":{"presence":[{"message":"can't be blank"}]},"submitter[email_address]":{"presence":[{"message":"can't be blank"}],"uniqueness":[{"message":"this email is already in use.","case_sensitive":false}]}}};
//]]></script>
  </body>
</html>
Contributor

bcardarella commented Dec 1, 2012

And why is there a form in the <head>?

ctuna commented Dec 1, 2012

Oh, good catch. My template was a little messed up. I moved the form into the body instead of the head. The first form is a search. Here is the new head.

 <head>
    <script src="/assets/prototype.js?body=1" type="text/javascript"></script>
    <script src="/assets/rails.validations.js?body=1" type="text/javascript"></script>
  </head>
Contributor

bcardarella commented Dec 1, 2012

Ok, well you are using prototype which the gem is not compatible with. You need to use jquery.

bcardarella closed this Dec 1, 2012

ctuna commented Dec 1, 2012

Wonderful! I changed the line from

= javascript_include_tag 'prototype.js'
to
= javascript_include_tag 'jquery.js'

and things are working now. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment