我想编辑我的rails应用程序,以便用户在输入日期时不再需要输入斜杠。该应用程序已将其配置为如果您键入社会安全号码,它会自动包含破折号。我认为它是相同的逻辑,应该是一个简单的解决方案。我尝试将以下代码放在我的应用程序中,但它根本没有更新。我还需要做些什么吗?我在代码行中进行了编辑,但没有任何改变。
以下是我所拥有的:
$(document).on('ajax:success','#new-member-button', function(event, response, status,xhr){
$('.search-member-area').hide();
$('#search-member').addClass('previous-stepp');
$("#member-details").addClass('selected');
$(response).appendTo($('.add-edit-member-area'));
maskField('#member_social_security_number', '999-99-9999', '___-__-____');
maskField('#member_phone_number', '999-999-9999', '(___) ___-____');
maskField('#member_date_of_birth', '99/99/9999', '__/__/____'); //piece of code I added
});
我编辑了social_security_number以确保将其取出,并且确实如此。但是当我在出生日期中添加auto_formatter时,它什么也没做。有什么想法吗?
编辑:看起来date_of_birth是DateTime,social_security_number是varchar(50)。关于如何使用DateTime执行此操作的任何想法?
编辑2:这是我的会员模特:
class Member < ActiveResource::Base
self.site = ServiceConfig[:vbr_service_uri]
self.element_name = 'member'
self.include_format_in_path = false
self.include_root_in_json = false
self.format = :json
validates_presence_of :first_name, :last_name, :date_of_birth, :social_security_number
validates_format_of :zip_code, with: /\A\d{5}(-\d{4})?$\z/, message: 'should be in the form 12345 or 12345-1234', :allow_blank => true
validates_format_of :phone_number, with: /\A(\d{3}-\d{3}-\d{4})?\z/, message: 'should be in the form 555-555-5555', :allow_blank => true
validates_format_of :social_security_number, with: /\A\d{3}-\d{2}-\d{4}$\z/, message: 'should be in the form 123-45-6789', :allow_blank => true
def full_name
"#{first_name} #{last_name}"
end
end