Created
March 12, 2012 12:55
-
-
Save stuartc/2021665 to your computer and use it in GitHub Desktop.
Revisions
-
stuartc created this gist
Mar 12, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ form_for(@user, :validate=>true) do |f| = f.label :birthdate = f.date_select :birthdate = f.text_field :birthdate, :type=>"hidden", 'data-validate'=>true end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ $('select[id^=user_birthdate]').live('blur', function() { setTimeout(function() { if ($('select[id^=user_birthdate]:focus').length == 0) { // update the hidden date var curYear = $('#user_birthdate_1i').val(), curMonth = $('#user_birthdate_2i').val(), curDay = $('#user_birthdate_3i').val(); hiddenDate = ""; if ((curYear * curMonth * curDay) != 0) { hiddenDate = curMonth + "-" + curDay + "-" + curYear; } var elem = $('input[id=user_birthdate]') elem.val(hiddenDate); elem.data('changed', true); // tells validator it changed elem.trigger('focusout'); // manually trigger focus out } }, 20); });