bcardarella/client_side_validations — Issue #197: Integration with ckeditor
Author: khelll
Created: 2011-10-11 10:16:48+00:00
State: open

I'm trying to use the validations with [ckeditor](https://github.com/galetahub/ckeditor) gem, which injects a rich textarea in place of the input field. I want to validate the length of the content in the rich text, but I'm unable to let the client side validation work at all.
I have added the following Ruby code, which is working fine:

```ruby
require 'Sanitize'
class RichTextValidator < ActiveModel::EachValidator
def validate_each(record, attr_name, value)
if Sanitize.clean(value.gsub(/\s|\u00A0/,'')).length < options[:minimum]
record.errors.add(attr_name, :too_short, options.merge(:count => options[:minimum]))
end
end
end
```
```ruby
validates :body, :rich_text=>{:minimum=>10} #works as expected
```

And then tried the following Javascript, which is not working:

```javascript
clientSideValidations.validators.local['rich_text'] = function(element, options) {
// Your validator code goes in here
alert(element.html())//it doesn't reach here.
if (element.val().empty().length