Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8092699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:20:32+00:00 2026-06-05T20:20:32+00:00

I need to add custom validator for comparing two dates – start date and

  • 0

I need to add custom validator for comparing two dates – start date and end date.
I created custom validator

class MilestoneDatesValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    if record.start_date > record.end_date
      record.errors.add(attribute, :end_date_less, options.merge(:value => value))
    end
  end
end

And I created ClientSideValidations custom validator. I wasn’t sure how I can get another attributes values in it, but I tried to do this in such way:

ClientSideValidations.validators.local['milestone_dates'] = function(element, options) {
  start_date = new Date($('#milestone_start_date').val());
  end_date = new Date($('#milestone_end_date').val());
  if(end_date < start_date) {
    return options.message;
  }
}

But it doesn’t work/ I have error only after reloading page, but not with client side validations.
I use client_side_validations (3.2.0.beta.3), client_side_validations-formtastic (2.0.0.beta.3), rails (3.2.3)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:20:33+00:00Added an answer on June 5, 2026 at 8:20 pm

    The code you supplied above is missing any mention of a declaration (and use) of a validator helper method. In the milestone_dates_validator.rb initializer try adding the following at the end of the file:

    module ActiveModel::Validations::HelperMethods
      def validates_milestone_dates(*attr_names)
        validates_with MilestoneDatesValidator, _merge_attributes(attr_names)
      end
    end
    

    And in your model call the validator on the attribute/s you are validating:

    validates_milestone_dates :milestone_ends_at
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to extend the TreeNode class such that I can add custom properties
I need to add a custom search engine to Firefox. I have a name
I have an XSL style sheet for which I need to add some custom
I am making a custom control I need to add some default keybindings, microsoft
I making a custom button, and I need to add a PreviewKeyDown event, whenever
I am using the Jquery Validation plug-in, however i need to add a custom
I simply need to add a validation class that limits a numerical entry from
I need to add custom context classesDirectory in applicationDirectory section to the .zfproject.xml .
I'm developing a web project where i need to add custom exception classes. For
I need to add custom validation(I think) for validating input from an user. Here's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.