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

  • SEARCH
  • Home
  • 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 7563507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:41:02+00:00 2026-05-30T13:41:02+00:00

I’m using jquery-ui datepicker on a User DOB field in a Rails 3.2 app.

  • 0

I’m using jquery-ui datepicker on a User DOB field in a Rails 3.2 app.

I’m trying to achieve the following:

  1. restrict the range of dates that can be selected, max = today, min = 100 years ago.
  2. initialize the datepicker with the date currently stored in the database (if any).
  3. display the selected date in a particular format in the dob text field.

My form looks like this:

<%= form_for @user do |f| %>
    <%= f.text_field :dob, :class=>'date-selector-dob', :value => (@user.dob.blank? ? '' : @user.dob.to_s(:long))  %>
<% end %>

where .to_s(:long) is the display format I’m after.

With the following javascript the datepicker works, the text field is properly formatted, but no max/ min date is set, and no initialization with the stored date occurs.

$(function (){  // enabledate picker
    $('.date-selector-dob').datepicker();
});

I added to this functions that I though would set min/max range and initialize, as follows:

$(function (){  // enable date picker
    $('.date-selector-dob').datepicker({minDate: new Date('-100Y'), maxDate: new Date('-1D')}); // enable datepicker and set range
    $('.date-selector-dob').datepicker('setDate', new Date($('.date-selector-dob').attr('value'))); // initialize datepicker with stored value

});

This is initializing the date picker correctly, but is not setting a min/max range. Is my approach incorrect?

In addition, the extended function resets my formatting string, and data is not displayed according to .to_s(:long). Using the basic function above, this formatting string is properly applied. What would cause this?

I’m pulling my hair out with this! I’d really appreciate it if someone can help me see whatever is it I’ve missed, and understand what I’m doing wrong. Thanks!

  • 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-05-30T13:41:03+00:00Added an answer on May 30, 2026 at 1:41 pm

    JavaScript’s Date doesn’t know what -100Y or -1D mean so your minDate and maxDate settings aren’t going to be anything that the datepicker will understand.

    From the fine manual:

    minDate

    Set a minimum selectable date via a Date object or as a string in the current dateFormat, or a number of days from today (e.g. +7) or a string of values and periods (‘y’ for years, ‘m’ for months, ‘w’ for weeks, ‘d’ for days, e.g. ‘-1y -1m’), or null for no limit.

    So you want this:

     $('.date-selector-dob').datepicker({
         minDate: '-100y',
         maxDate: '-1d'
      });
    

    Demo: http://jsfiddle.net/ambiguous/RQgCW/

    If you want the datepicker to use a certain format for the date, use the dateFormat option:

    The format for parsed and displayed dates. This attribute is one of the regionalisation attributes. For a full list of the possible formats see the formatDate function.

    Also, you should be able to skip this:

    $('.date-selector-dob').datepicker('setDate', new Date($('.date-selector-dob').attr('value')))
    

    and just set the <input>‘s value attribute to the date (preferably in ISO 8601 format), then the datepicker should be able to take it from there on its own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.