Decidim User Fields
Add custom user fields through a configuration file and without migration.
This module aims to configure in a blast new fields for subscription and profile editing. It supports:
- User registration
- User profiles
- User invitations
⚠️ It does not support:
Set up the module
Add the gem to your Gemfile
gem "decidim-user_fields"
Run bundle
bundle install
Create an initializer config/initializers/custom_user_fields.rb
Decidim::CustomUserFields.configure do |config|
config.add_field :birthdate, type: :date, required: true
config.add_field :province, type: :select, options: [:vd, :vs, :ar], default: :vd, required: true
config.add_field :address, type: :textarea, required: false, rows: 10
config.add_field :purpose, type: :text, required: false
end
Available field types
:date
parameters:
required
: must choose a datemin
: date in ISO8601 where the user cannot select beforemax
: date in ISO8601 where the user cannot select after
:textarea
parameters:
required
: if the field is requiredmin
: minimal lengthmax
: maximal lengthrows
: how many rows the field should display
:text
parameters:
required
: if the field is required
Labels
Labels are translated and are under the translation scope decidim.custom_user_fields
.
Example of a fr.yml
file:
fr:
activemodel:
attributes:
user:
birthday: "Birthday"
address: "Address"
purpose: "Reason for Being Here"
province: "Canton"
decidim:
custom_user_fields:
province:
options:
vd: "Vaud"
vs: "Valais"
ar: "Aarau"
Run locally
To run this module locally, we use Docker-compose:
docker-compose up
This will run a decidim-user_fields container, which sleeps.
You can run any command you want in the running container, like:
Command | Description |
---|
docker-compose exec -it decidim-user_fields bundle exec rails db:seed | Seed the database (run on localhost:3000) |
docker-compose exec -it decidim-user_fields bin/webpack-dev-server | Compile assets and watch for changes |
docker-compose exec -it decidim-user_fields bin/rails s -b 0.0.0.0 | Run the Rails server in development |
docker-compose exec -it decidim-user_fields bundle exec rspec /home/decidim/module/spec | Run tests for the module |
docker-compose exec -it decidim-user_fields bundle exec rubocop -a /home/decidim/module | Correct lint errors with RuboCop |
docker-compose exec -it decidim-user_fields bash | Navigate your container in bash |
While developing locally, you have two environment variables that can help you:
ROOT
: the root of the application using the moduleMODULE_ROOT
: the place where your gem code is.