Merge pull request #231 from wvengen/feature-autocomplete-fixes-2

fix user form field order and autocompletion
This commit is contained in:
wvengen 2013-12-30 02:03:48 -08:00
commit 4f80fd0e8c
6 changed files with 34 additions and 8 deletions

View file

@ -121,6 +121,15 @@ $(function() {
$(this).children('input[type="submit"]').attr('disabled', 'disabled'); $(this).children('input[type="submit"]').attr('disabled', 'disabled');
}); });
// The autocomplete attribute is used for both autocompletion and storing
// for passwords, it's nice to store it when editing one's own profile,
// but never autocomplete. Only implemented for passwords.
$('input[type="password"][autocomplete="off"][data-store="on"]').each(function() {
$(this).on('change', function() {
$(this).removeAttr('autocomplete');
});
});
// Use bootstrap datepicker for dateinput // Use bootstrap datepicker for dateinput
$('.datepicker').datepicker({format: 'yyyy-mm-dd', language: I18n.locale}); $('.datepicker').datepicker({format: 'yyyy-mm-dd', language: I18n.locale});

View file

@ -203,5 +203,5 @@ module ApplicationHelper
:title => I18n.t('helpers.application.write_message') :title => I18n.t('helpers.application.write_message')
end end
end end
end end

View file

@ -0,0 +1,13 @@
module SharedHelper
# provide input_html for password autocompletion
def autocomplete_flag_to_password_html(password_autocomplete)
case password_autocomplete
when true then {autocomplete: 'on'}
when false then {autocomplete: 'off'}
when 'store-only' then {autocomplete: 'off', data: {store: 'on'}}
else {}
end
end
end

View file

@ -1,5 +1,5 @@
= simple_form_for([:admin, @user]) do |f| = simple_form_for([:admin, @user]) do |f|
= render 'shared/user_form_fields', f: f = render 'shared/user_form_fields', f: f, password_autocomplete: false
.form-actions .form-actions
= f.submit = f.submit
= link_to t('ui.or_cancel'), :back = link_to t('ui.or_cancel'), :back

View file

@ -6,7 +6,7 @@
= h(t('.user.title', user: show_user)) = h(t('.user.title', user: show_user))
%small= t '.user.since', when: distance_of_time_in_words(Time.now, @current_user.created_on) %small= t '.user.since', when: distance_of_time_in_words(Time.now, @current_user.created_on)
= simple_form_for(@current_user, :url => update_profile_path) do |f| = simple_form_for(@current_user, :url => update_profile_path) do |f|
= render :partial => 'shared/user_form_fields', :locals => {:f => f} = render :partial => 'shared/user_form_fields', :locals => {:f => f, :password_autocomplete => 'store-only'}
.form-actions .form-actions
= submit_tag t('ui.save'), class: 'btn' = submit_tag t('ui.save'), class: 'btn'
.span5 .span5

View file

@ -1,12 +1,16 @@
- if FoodsoftConfig[:use_nick]
-# use_nil option to user model validators break required mark
= f.input :nick, required: true
= f.input :first_name = f.input :first_name
= f.input :last_name = f.input :last_name
= f.input :email = f.input :email
-# need :required because :use_nil option on user model validators break the required mark
= f.input :nick, required: true if FoodsoftConfig[:use_nick]
-# You can control password autocompletion by passing `password_autocomplete` to this partial.
-# Possible values: undefined/nil, true, false, 'store-only'
-# see also https://github.com/foodcoops/foodsoft/wiki/Form-autocompletion
- password_autocomplete = nil unless defined?(:password_autocomplete)
- password_html = autocomplete_flag_to_password_html(password_autocomplete)
= f.input :password, :required => f.object.new_record?, input_html: password_html
= f.input :password_confirmation, :required => f.object.new_record?, input_html: password_html
= f.input :phone = f.input :phone
= f.input :password, :required => f.object.new_record?
= f.input :password_confirmation
= f.simple_fields_for :settings_attributes do |s| = f.simple_fields_for :settings_attributes do |s|
= s.simple_fields_for :profile, defaults: { inline_label: true } do |profile| = s.simple_fields_for :profile, defaults: { inline_label: true } do |profile|