Comments (4)
I seem to be experiencing this issue, but only in development
, not in production
. I have looked everywhere for possible configurations in the environments that could account for the difference but I can't find it anywhere. Any ideas?
from simple_form.
I'm having the issue in both development
and test
environments. It appears to be related to how Rails lazy-loads classes in those environments vs. eager loading in production. My current quick-and-dirty work-around is to reference the custom input class names in an initializer, e.g.:
config/iniitilizers/simple_form.rb
# ...
SimpleForm.setup do |config|
# ...setup stuff here..
end
# Added at the bottom of the file
# Explicitly reference the custom input classes
CurrencyInput
CustomInput
MultiValueInput
# End of File
Alternatively, it also works to locally override the SimpleForm::FormBuilder#attempt_mapping
method with the code from v5.2.0:
simple_form/lib/simple_form/form_builder.rb
Lines 673 to 681 in 4851758
This works because it always attempts to load the class and raises an error if it's not present.
As opposed to the v5.3.0 version which never executes because the lazy loaded class constant isn't loaded, and therefore isn't defined yet:
simple_form/lib/simple_form/form_builder.rb
Lines 673 to 677 in 8f77f59
from simple_form.
I use a custom form builder that has custom fields defined in it and this change breaks it too.
It seems the change will pass the specs but you won't see it break unless you actually have custom inputs or custom form builder in your dev environment.
The intention of the calling method find_mapping
attempts to map a field name to an input class and it usually finds it before getting to the attempt_mapping
method. The attempt_mapping
method is reached when you defined some custom field hence you have to have a custom input class or have it defined in a custom form builder. These are loaded lazily in dev so the code change that broke it made the method not do what it was supposed to do.
So, for general input types attempt_mapping
not being called.
If you do not want this feature, you'd simply set inputs_discovery
option to false.
You can also create a custom builder and map custom input classes using map_type
class method.
Or there may a configuration option to map as well such that attempt_mapping
is not called (not sure this exists).
The try catch is used because it is attempting to find a class as the method name implies.
If the argument for the change is performance, you'd only see little improvement unless you have a ton of custom inputs. So, to me the change is not really worthwhile and should be reverted.
from simple_form.
Related Issues (20)
- Is there any particular reason for the use of `%%` instead of `%` in the ERB template? HOT 2
- @builder.input_field(:license_plate, type: 'radio' .... ) output a textarea tag instead of an inpt HOT 1
- Broken Link in Readme File for Bootstrap Live App example HOT 4
- Chrome error: label's for attribute doesn't match any element id
- Bootstrap floating labels keep floating even without input HOT 1
- Auto reload configuration HOT 3
- `config.default_form_class` should not be *overriden* but *complemented* when `html: { :class }` is specified HOT 1
- Redundant aria-required on required fields HOT 1
- Rails 7.1 updated password validation changed rendering of password inputs
- Custom Component raise an error with rails 7.1 and zeitwerk HOT 1
- Hints don't work on the namespaced model HOT 1
- Encrypted attributes always default to textarea
- Proposal for customizable classes merging
- The custom `error:` on all inputs does not work if there is an object present
- Multiple inputs with the same name generate unparseable names in Rails >= 7.1.1
- <div class="checkbox"> <input value="false" type="hidden" name="meal[completed]"> <input class="boolean optional" type="checkbox" value="true" checked="checked" name="meal[completed]" id="meal_completed"> <label class="boolean optional" for="meal_completed">Completed</label> </div>Update: This bug only appears if you have custom value for `unchecked_value`. In this case `unchecked_value: false` HOT 1
- https://simple-form-bootstrap.herokuapp.com/ is Down HOT 1
- Label's for attribute doesn't match the id when nil is given in collection
- Adding a data-x attribute to the root <form>? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple_form.