Giter Site home page Giter Site logo

client_side_validations's People

Contributors

akelmanson avatar amangale avatar anandbait avatar arr-ee avatar bcardarella avatar carlosramireziii avatar cwjenkins avatar dependabot-preview[bot] avatar dependabot[bot] avatar fgrehm avatar godisemo avatar ilyakatz avatar ivanoats avatar jarkko avatar jaynetics avatar jonkessler avatar joshweinstein avatar libc avatar maintux avatar mhenrixon avatar mikdiet avatar mikebaldry avatar mjtko avatar mlyubarskyy avatar mvastola avatar onomojo avatar pfeiffer avatar pranas avatar taavo avatar tagliala avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

client_side_validations's Issues

Formtastic selects don't validate required.

Not a single one of my selects are validated for required.

Code usually looks something like this:
=f.inputs name: locals[:name] do
=f.input :price, label:'Price/Cost', input_html: { maxlength:10, size: 10 }
=f.input :currency, as: :select, collection: major_currencies(Money::Currency::TABLE)
=f.input :type, as: :select, collection: ['Cost', 'Price']

Let's say currency is a required feel it doesn't matter because it don't get validated. Do I need to select nothing for the validation to take? I usually have "Please select something" as the preselected value and my guess is that that is what is causing problems.

Turn off validation for fields_for?

Is it possible to turn off validation for nested fields/associations in an easy manner? I try with the following below but preferably I'd like the possibility to turn it off for the whole darn thing inside the f.semantic_fields_for :address, validate: false do

=f.semantic_fields_for :delivery_address do |address| 
  =address.inputs name:"Delivery Address" do
    =address.input :street_one, validate: false
    =address.input :street_two, validate: false
    =address.input :city, validate: false
    =address.input :zip, validate: false
    =address.input :region
    =address.input :country, validate: false
    =address.input :type, as: :hidden
    =address.input :addressable_type, as: :hidden
    =address.input :addressable_id, as: :hidden 

Is something like that already implemented or is it behind the monitor again? I wouldn't mind supplying a patch if I just knew where to start hacking :)

Field errors always generated the formtastic way.

Hi,

I uncommented the code in the client_side initializer but for required fields it is always using the formtastic error message instead of the client side error. Even though I turned off generation of error messages with formtastic to let client_side generate that for me. For my email validator it works fine if I write something in the field but if I leave it empty I get the ugly formtastic message with

https://gist.github.com/923838

Errors don't disappear after change has been made.

Not sure if the issue is infront of the screen or with formtastic or with client_side_validations but when my validations pass the error message don't disappear. I am probably doing something wrong but I can't figure out what.

If I miss to enter a name that is required I get a message saying: "can't be blank" but when I enter something in that textbox the message don't go away. Is this something I am supposed to code myself?

IE support

Not really an issue, just heads up - I'm using this gem on Windows Ruby 1.9.2p180 Rails 3.0.5, developing an app that must support IE6 ( 6.0.2900.5512 ) & IE 7 ( which I noticed you haven't tested under) - so far no problems.

All default validations & custom validations ( like url and email format work fine), under IE 6, 7 & 8.

Thank you very much for a great gem.

SimpleForm component order

Currently ClientSideValidations assumes the :error message to be the last in the stack. However, SimpleForm allows this order to be overridden. The order should be respected.

Not working for Devise gem validations

Hi,

I am using devise gem for authentication and for signup, but this gem is not showing the error messages for the fields whose validations are written inside devise gem.
E.g validates_presence_of :email is not working initially but if write the same in user model it shows the error message. Do i need to override all the validations in user model ?? or is there any other work around for this ?

undefined method `each' for "":String (mongoid/middleware.rb:13:in `is_unique?' ruby1.9.2)

Hi Brian!

When I fire a
http://127.0.0.1:3000/validators/uniqueness.json?case_sensitive=true&scope=&user[email]=user10%40mail.com

I get an
undefined method `each' for "":String

error here:
lib/client_side_validations/mongoid/middleware.rb:13:in `is_unique?'

That's this line:
(params[:scope] || {}).each do |key, value|

Could it be, that in this case params[:scope] is not a Hash but a string and ruby1.9.2 bails out?
--Frank

jQuery Mobile Support

There seem to be several issues before this will work.

  1. Because the pages are loaded via AJAX the forms can be inserted into the DOM without the .validate() function running. (currently runs after page load) I'll probably have to use the 'ajaxComplete' event.
  2. Even when forcing the form to setup after it is inserted in the DOM the form seems to be running validation right away.

Allow input on validation fail with warning or fuzzy validation.

Hi, Brian.

Been playing with the new releases and everything seems to be kosher . (By the way - no issues under FF 4 so far) however I'm back with a new idea :-)

I guess this is a feature request. Sometimes there are situations where user input doesn't necessarily pass part of your validation but can still be legitimate input. You want to be able to let the form be able to be submitted but let a user know that it is potentially invalid or mistyped input, so they check it twice.

This is from a real life app I worked on a while back, and it can serve as a great example. There was a vehicle parts order table, where users were required to provide a VIN number of the vehicle. Unfortunately the VIN db that we used to verify the VIN numbers would only hold 3 years worth of VIN numbers. We had to verify against that external service (customer requirement), however if the vehicle was older than 3 years it was mostly like not in the DB, while still having a legitimate VIN number. So in that case we would verify requirements like "17 alphanumeric characters long" but since we couldn't verify the actual existence of a VIN, we would use some javascript voodoo to pop a warning for them on field blur to make sure they verify the number (actually a little yellow div that asked them politely to verify the number was typed in correctly since it wasn't in our records)

Another example is if you want users to provide full legal names, but most people tend to submit things like Mike vs Michael, and you want to emphasize it to them that it's valid input but you want them to verify that it's their legal name. Sort of a fuzzy validation (tm) :-)

I'm sure there are other situations where it would be useful to let through a form that passes some validation but fails some more obscure ones with a warning. Or allow validations that would be "nice to pass". What do you think about it?

One more thing - what if your validation depends on external service that happens to be down. You may still want to be able to process the form even if it fails validating against that service.

Once again thanks for a great gem.
Nick

:unless on :numericality is still generating client side validation

I have the following validator:

validates :price
:numericality => { :greater_than => 0 },
:unless => Proc.new { |item| xxxxxx }

I removed the proc body for simplicity. This still generates client side validation, however. I assume that should not be the case based on documentation.

Validator callbacks

There should be callbacks on the validators. I propose the following:

element:validate:before
element:validate:after
element:validate:pass
element:validate:fail

form:validate:before
form:validate:after
form:validate:pass
form:validate:fail

Custom validations Rails 3 style.

Hello.

I have validations that are done in the following way:

validates :email, :presence => true, :length => {:minimum => 5, :maximum => 50}, :email_format => true

I also have a custom validator

class EmailFormatValidator < ActiveModel::EachValidator
  def validate_each(object, attribute, value)
    unless value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
      object.errors[attribute] << (options[:message] || "is not formatted properly. Try something like: [email protected] ")
    end
  end
end

Client_side_validations - validates my field for minimum / maximum , but not :email_format , which is just handled by server-side validation on submit.

Is this intended behavior or am I missing something? I saw the custom validations wiki page, just wondering if this setup ( like in my example) is going to be supported - this would make the usage of validates_email method ( as in your example on wiki page) unnecessary it seems.

Formtastic sub builder

Hi,

Formtastic offers a way at the end of it's initializer file to easily extend it's form builder, in my case, I wanted to add a few class along the way in some cases, but the thing is that the builder is MyApp::FormBuilder, which is not recognized by the javascript as a builder. Right now, I added :

def self.client_side_form_settings(options, form_helper)
  {
    :type => self.superclass.to_s,
    :inline_error_class => ::Formtastic::SemanticFormBuilder.default_inline_error_class
  }
end

to my builder so that it gets the right class name. But it's now something else that I have to look for when upgrading...

I don't really understand why it's "super.to_s" in the first case and not "Formtastic::SemanticFormBuilder" right away as it's already written verbatim on the following line :-)

Conditionally ignore validations per input

It would be nice to ignore individual validations on each form input:

= simple_form_for @user do |user|
  = user.input :email, :validate => { :ignore => [:uniqueness] }

'Password' confirmation message

I don't think the confirm password message is so useful. It should appear on the confirm field, not on the password field.

validates_with causes TypeError

On my model, I have a custom validates_with validator.

With this in place, I get a TypeError with the message, "nil is not a symbol". If I remove the validator from the model, it appears to work fine.

Thanks,
Scott

can't iterate from Float

I have a model with a float attribute and when I turn csv on for its form I get the following type error:

can't iterate from Float

Removing this field from the form makes everything work as expected.

I'm on Rails 3.0.5 using ActiveRecord, form_for and csv gem 3.0.0.beta.7.

Readme typo

Since it's a minor typo I didn't feel like forking & pull request:

rails g client_side_validations:instlal should be rails g client_side_validations:install

Rails 3.1 Engines to serve Javascript file

Having to run the install generator every time is pretty annoying. When Rails 3.1 drops Client Side Validations should take advantage of the new Engines to serve the asset from the gem instead of copying it into public/javascript

fields_for validation

If I omit :validate => true from a fields_for call, a NoMethodError is thrown:

= fields_for @wine.wine_region do |wine_region_form|

However adding it does not throw an exception:

= fields_for @wine.wine_region, :validate => true do |wine_region_form|

However, no validation for nested properties is generated.

Unexpected behavior on [data-failed-once]

Brian, here is a little issue I discovered. It has more to do with user experience.

You know how when you are filling in a form for common fields (name, email, address), most browsers provide little drop down with history of what you filled in before? Well if you tried to fill a line, and it failed validation after you tabbed away from it and then came back to it, that dropdown will try to help you again. But [data-failed-once] keyup event keeps refreshing the field trying to validate it, as you type. As a result it keeps flickering which is very annoying, plus it's not letting user to use the browser dropdown.
Also trying to force the dropdown on keydown, also doesn't work. Although - that seems to be an issue in firefox, not chrome.

I see why would you want to validate as you type, but then it creates unpleasant experience, especially for people who are used to reusing value from that dropdown. I think the expected behavior would be to validate on blur, maybe? What do you think? Or is there a way to disable the dropdown altogether, so at least it's not confusing?

I'm not sure if it qualifies as bug, rather than a unexpected feature :-)

Validations firing at wrong time?

My form has a text field and a textarea next to each other.

<%= form.label :duration, "Duration (hours)", :class => "required" %>
<%= form.text_field :duration, :autofocus => true %>
<%= form.label :description, "Description", :class => "required" %>
<%= form.text_area :description %>

Both are required and the textarea has an additional uniqueness test on it.

When I leave the text field empty and click on the textarea it invalidates both of them. I never get the textarea focused and have to click on it again.

This same effect affects the submit button. When I fulfill both the text field's and textarea's validation requirements and click on the submit button it does not submit the form. Instead, it validates the once-invalid fields and I have to click submit a second time to actual submit the form.

I realize this description might be lacking in clarity. I can shoot a quick screencast if it would help.

You're firing validation on the "focusout" event. This problem could be related to when that event actually triggers. Let me know if I can troubleshoot in any way.

I'm on latest master as of: d6db7fc

try to require ActiveModel if ActiveRecord is not defined

I don't use ActiveRecord in my project, but I use ActiveModel (Validations) and had problem with gem. In /lib/client_side_validations.rb you should check if ActiveModel is defined if ActiveRecord is not defined, i.e.:

if defined?(::ActiveRecord)
require 'client_side_validations/active_record'
elsif defined?(::ActiveModel)
require 'client_side_validations/active_model'
end

class="field_with_errors", but nothing there

Hi! I hav some trouble with this. When I enter invalid data - class of div changed to field_with_errors, but does not appear any error messages. Why can this be? Rails 3.0.4

undefined method `client_side_validation_hash'

Hi,

i m getting this error with mongoid

my gems:

gem 'rails'

gem 'haml-rails'
gem 'compass', '>= 0.10.6'
gem 'jquery-rails', '>=0.2.6'
gem 'formtastic'
gem 'client_side_validations', '~> 3.0.0'

gem 'mongoid'
gem 'bson_ext'
gem 'kaminari'

gem "bcrypt-ruby", :require => "bcrypt"
gem "cancan"


my form:
= semantic_form_for @user, :validate => true do |f|
=f.inputs do

trace:
mongoid (2.0.1) lib/mongoid/attributes.rb:159:in method_missing' client_side_validations (3.0.4) lib/client_side_validations/action_view/form_builder.rb:81:inapply_client_side_validators'
(eval):2:in text_field_with_client_side_validations' formtastic (1.2.3) lib/formtastic.rb:655:inbasic_input_helper'
formtastic (1.2.3) lib/formtastic.rb:660:in string_input' formtastic (1.2.3) lib/formtastic.rb:1280:ininline_input_for'
formtastic (1.2.3) lib/formtastic.rb:132:in block in input' formtastic (1.2.3) lib/formtastic.rb:131:inmap'
formtastic (1.2.3) lib/formtastic.rb:131:in `input'

i did the installation as said in the wiki
initializer got created

any idea?

best regards

Issues with nested forms

I'm not sure exactly how to pinpoint exactly what's wrong here, but I gather that it's because I have a nested form.

My models are:

Company has_many :employees
Employee belongs_to :company

I have a nested form for my company#new action that also creates the first employee. I'm using f.fields_for :employees do accomplish this.

Here's what I'm seeing:

  • The validates_presence_of validators are working as expected, as are the validates_format_of (VERY helpful).
  • The "must match" validator on password ends up causing lots of "$this[0] doesn't exist" javascript errors.
  • The uniqueness validator on Company#name fires off an ajax request... that seems to not be caught by your middleware.

If this is a bug, happy to contribute a fix. Just need a point in the right direction.

Validates on :presence => false, for custom validations.

Hello.

There are few items on the forms, that are optional, but if provided should be validated.
i.e.: I have a url in a contact form, that should be validated as valid ( pass regex (using custom validation) & maximum limitations), but if not provided, the field shouldn't be validated.

Works fine on server-side validations, but not client side. Keeps checking the field, no matter what I do. I even tried to set :presence => :false explicitly and still it keeps checking the field. this seems to be an issue only on fields that use custom validation. I have a field called company, that only validate :company, :length => {:maximum => 50}
and this one seems ok.

here is my regex: /[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/i

Unless I missed setting up some option - that seems like a small bug to me.

Client side validations killing events from jquery datapicker/some custom masks

After an error all events from my input are missing.

As i took a quick look at the code a lot of replaces is going on and i think somewhere all events are gone. I wasnt abble to fix it so i am opening this issue.

Another thing that i did noticed is that if you try to submit the form you get an error for the first time, but if you try again, the form is submitted.

Mongoid Uniqueness

The Mongoid Uniqueness validator is pretty limited. This won't be a block for a 3.0 release. Should be done for a 3.0 patch release.

Select errors sometimes don't get cleared.

Potential problem with selects again. Some of my selects are not cleared even after selecting a value. See https://gist.github.com/949020 for more information. The haml file is what I use and the html file is what is generated. For frame_id and color_id the error refuses to go away regardless what I select. For lens_tint_id the error goes away when I select something except the "" blank option.

I am a little unsure about where the problem is exactly. If I fill in all required fields in that form I still can't post it back to the server but if I turn client side validations off then server side validation says it is ok. What more information can I provide?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.