
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
dependent-fields-rails
Advanced tools
DependentFields makes it easy to hide or show dependent fields in forms based on select or checkbox values.
Add gem 'dependent-fields-rails'
to your Gemfile.
Run bundle install
.
Add //= require dependent-fields
to your Javascript manifest file (usually found at app/assets/javascripts/application.js
).
Bind events, for example with jquery:
$(document).ready(function() {
DependentFields.bind()
}
Restart your server and everything should be set up. See Usage below on how to declare your dependent fields in views.
Be sure to include underscorejs and jquery in your page.
Dependent Fields may depend on select or checkbox input elements. You have to surround your dependent fields with
a div
with class js-dependent-fields
.
The examples below are written in the slim template language with simple_form. But you can use dependent-fields with every other template language out there.
Note the data attributes on the js-dependent-fields div.
= simple_form_for(@filing) do
= f.input :registration_office, collection: ['habm', 'dpma']
.js-dependent-fields[data-select-id='filing_registration_office' data-option-value='habm']
= f.input :language, collection: ['english', 'german']
The language selector will only be shown if the user selects 'habm' in the registration office.
You can also specify multiple option values by seperating them with |
. For example: data-option-value='habm|dpma'
Note the data attributes on the js-dependent-fields div.
= simple_form_for(@filing) do
= f.input :priority_enabled
.js-dependent-fields[data-checkbox-id='filing_priority_enabled' data-checkbox-value='true']
= f.input :priority_date
= f.input :priority_filing_nr
The date and filing_nr fields will only be shown if the user checks the priority_enabled field.
Relevant radio inputs are selected by name and not by id, because radio inputs in the same group have different ids but the same name. Note the data attributes on the js-dependent-fields div.
= simple_form_for(@filing) do
= f.input :registration_office, collection: ['habm', 'dpma'], as: :radio_buttons
.js-dependent-fields[data-radio-name='filing[registration_office]' data-radio-value='habm']
= f.input :language, collection: ['english', 'german']
The language selector will only be shown if the user selects 'habm' in the registration office.
You can also specify multiple option values by seperating them with |
. For example: data-radio-value='habm|dpma'
Add data-method='disable'
to the js-dependent-fields div.
make it compatible with rails4. thanks to mcbridejc for the pull request.
fix escaping of attribute names. thanks to nagyt234 for the pull request.
FAQs
Unknown package
We found that dependent-fields-rails demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.