Make the birthday field a date field
And remove the date picker (you can now use the native one)
This commit is contained in:
parent
8126549a0d
commit
6cb78acd85
3 changed files with 51 additions and 15 deletions
|
@ -122,7 +122,7 @@ class Users::DossiersController < UsersController
|
|||
@facade = facade params[:dossier][:id]
|
||||
|
||||
if checked_autorisation_donnees?
|
||||
unless Dossier.find(@facade.dossier.id).update_attributes update_params
|
||||
unless Dossier.find(@facade.dossier.id).update_attributes update_params_with_formatted_birthdate
|
||||
flash.alert = @facade.dossier.errors.full_messages.join('<br />').html_safe
|
||||
|
||||
return redirect_to users_dossier_path(id: @facade.dossier.id)
|
||||
|
@ -171,6 +171,25 @@ class Users::DossiersController < UsersController
|
|||
params.require(:dossier).permit(:id, :autorisation_donnees, individual_attributes: [:gender, :nom, :prenom, :birthdate])
|
||||
end
|
||||
|
||||
def update_params_with_formatted_birthdate
|
||||
editable_params = update_params
|
||||
|
||||
# If the user was shown a date input field (if its browser supports it),
|
||||
# the returned param will follow the YYYY-MM-DD pattern, which we need
|
||||
# do convert to the DD/MM/YYYY pattern we use
|
||||
if editable_params &&
|
||||
editable_params[:individual_attributes] &&
|
||||
editable_params[:individual_attributes][:birthdate] &&
|
||||
editable_params[:individual_attributes][:birthdate] =~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/
|
||||
|
||||
original_birthdate = editable_params[:individual_attributes][:birthdate]
|
||||
formatted_birthdate = I18n.l(original_birthdate.to_date, format: '%d/%m/%Y')
|
||||
editable_params[:individual_attributes][:birthdate] = formatted_birthdate
|
||||
end
|
||||
|
||||
editable_params
|
||||
end
|
||||
|
||||
def checked_autorisation_donnees?
|
||||
update_params[:autorisation_donnees] == '1'
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue