DavyJonesLocker / client_side_validations

Client Side Validations made easy for Ruby on Rails
MIT License
2.69k stars 404 forks source link

No validations with simple Rails form #810

Closed resistorsoftware closed 3 years ago

resistorsoftware commented 3 years ago

Steps to reproduce*

Rails 6, installed client_side_validations gem 17.0

Expected behavior*

Expecting to see client-side validation because in the browser console if I query for the object ClientSideValidations it exists.

Active Record is working server-side:

x = Shop.create(domain: 'doo')
=> #<Shop:0x00007fa6f7628978 id: nil, domain: "doo", token: nil, created_at: nil, updated_at: nil, collection_id: "", brand_name: "">
[4] pry(main)> x.errors
=> #<ActiveModel::Errors:0x00007fa6f4f2e340
 @base=#<Shop:0x00007fa6f7628978 id: nil, domain: "doo", token: nil, created_at: nil, updated_at: nil, collection_id: "", brand_name: "">,
 @details={:token=>[{:error=>:blank}], :brand_name=>[{:error=>:blank}]},
 @messages={:token=>["can't be blank"], :brand_name=>["can't be blank"]}>

Actual behavior*

There is zero influence on the client form. It is as if nothing has been added. No client side verification happens

System configuration*

Rails version: 6.0.3.3

Ruby version: 2.6.5

Client Side Validations version: 17.0

Code snippet from your model of the validations*

class Shop < ApplicationRecord
  has_many :connections
  has_many :users, through: :connections
  validates :domain, :token, :brand_name, presence: true
end

The whole form code from your template*

<%= form_with model: @shop, validate: true do |f| %>

<%= f.label :domain %>
<%= f.text_field :domain, class: 'form-control m-2' %>
<%= f.label :token %>
<%= f.text_field :token ,class: 'form-control m-2' %>
<%= f.label :brand_name %>
<%= f.text_field :brand_name ,class: 'form-control m-2' %>
<%= f.submit 'Submit', class: 'btn btn-outline-dark mb-2' %>

<%end%>

The resulting HTML*

<form action="/shops/new" accept-charset="UTF-8" data-remote="true" method="post"><input type="hidden" name="authenticity_token" value="redacted">
  <div class="field form-group">
      <label for="domain">domain</label><br>
      <input class="form-control m-2" type="text" name="domain" id="domain">
  </div>
  <div class="field form-group">
      <label for="token">token</label><br>
      <input class="form-control m-2" type="text" name="token" id="token">
  </div>
  <div class="field form-group">
      <label for="brand_name">Brand name</label><br>
      <input class="form-control m-2" type="text" name="brand_name" id="brand_name">
  </div>
  <div class="actions">
      <input type="submit" name="commit" value="Submit" class="btn btn-outline-dark mb-2" data-disable-with="Submit">
  </div>
</form>

Browser's development console output*

Additional JavaScript Libraries*

Repository demostrating the issue

Debugging CSV issues is a time consuming task. If you want to speed up things, please provide a link to a repository showing the issue.


* Failure to include this requirement may result in the issue being closed.

tagliala commented 3 years ago

Hi!

Thanks for being part of the CSV Community.

The generated HTML is completely missing the data attribute with CSV validations: you should see a data-client-side-validations attribute in the <form> tag.

The most probable reason is that the node package is present in package.json but the ruby gem is missing in Gemfile.

Debugging CSV issues is a time consuming task, after you confirm that gem 'client_side_validations', '~> 17.0' has been added to your Gemfile, to speed up things, you could provide a repository with a reproducible test case

resistorsoftware commented 3 years ago

The ruby gem is not in fact missing, I stated in my explanation that version 17 is present and in the gem lockfile, and the initializer is present, and I uncommented the ActionView::Base monkeypatch that looks for labels and replaces their HTML etc.

As for a reproducible test case,I will just leave it here... why does the HTML render a form with no data attributes? It seems that is the job of the gem, the gem is installed, and the initializer is in place. Is there some other configuration that has to happen?

tagliala commented 3 years ago

As for a reproducible test case,I will just leave it here... why does the HTML render a form with no data attributes?

I cannot reproduce

It seems that is the job of the gem, the gem is installed, and the initializer is in place. Is there some other configuration that has to happen?

Nope

resistorsoftware commented 3 years ago

Ok.. thanks anyway. I will abandon this gem approach and go with formik... I know that library works!