-
Notifications
You must be signed in to change notification settings - Fork 158
Set default values for min/max handler #4627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
2cb2fed
74793dd
9d847ca
9f28346
98ac95b
fe20726
0b26bcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,14 +42,21 @@ def create_widget(form, attrib, format: nil, hide_excludable: true, hide_fixed: | |
| end | ||
|
|
||
| # Append a wrapper div to hold additional info | ||
| data = { | ||
| widget_type: widget, | ||
| hide_by_default: attrib.hide_by_default? | ||
| } | ||
|
|
||
| min_val = attrib.opts[:min] | ||
| max_val = attrib.opts[:max] | ||
| data[:min_default] = min_val if min_val | ||
| data[:max_default] = max_val if max_val | ||
|
|
||
| wrapped = content_tag( | ||
| :div, | ||
| id: [form.object_name, attrib.id, 'wrapper'].join('_'), | ||
| class: attrib.hide_by_default? ? 'd-none' : '', | ||
| data: { | ||
| widget_type: widget, | ||
| hide_by_default: attrib.hide_by_default? | ||
| } | ||
| data: data | ||
|
||
| ) do | ||
| rendered | ||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think storing the min/max here might add a bit more complexity than we need, as it requires us to keep conventions between server-side and client-side code, which is difficult as we can't share any methods between ruby and javascript. We can expand this initial hash whenever necessary ofc, but things like mins and maxes shouldn't need to be collected at this stage since we know the widget will be ok when it renders. IMO it would be much easier to manage if all of this was handled in
dynamic_forms.js, and we load the default values into the data hash whenever we bind the min/max-for listener. This also prevents us from expanding the data hash for static widgets (without min/max-for directives), where this info is unnecessary bloat.Just to justify the existing items under this criteria,
widget_typeis necessary because we don't have any other way of connecting the complex form items (like resolution_fields) to a meaningful name. The hide_by_default attribute is less necessary admittedly, but ok because we absolutely have to checkhide_by_default?when we add thed-noneclass, and it is simpler to just get it from the attrib object here than detect it from thed-noneclass later.Let me know what you guys think of this, obviously the wrapper is new so we could go several ways with what it becomes, and this current approach does reduce complexity in
dynamic_forms, which is definitely already complex enough. Overall though I think trying to avoid creating conventions that have to be followed in two places will save us some headache as we use this more.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I follow you. It needs to be rendered in the HTML on the server side somewhere at some point. But I could be completely missing what you're trying to say.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am saying that unless the
datainformation needs to be rendered server-side for some reason, we should store and retrieve that data exclusively in the javascript, just to keep that storing and retrieval in a single place. Since we can get the min and max information from the html post-rendering, this would be a place where we could just as effectively gather and store min_default and max_default inaddMinMaxForHandlerand set the element's data in the same way, allowing us to only store data on widgets that we are going to change dynamically later, and keep min/max-for functionality entirely withingdynamic_forms.js.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I think I got you - because mins and maxes will be in the HTML before any of our javascript runs that's when & where we can extract it. I.e., the defaults are there before we modify them when our handlers run. Is that it?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. And even though the resulting
dataattribute will be the same by the time we start changing the mins/maxes, we should still try and set this at the latest possible moment, since that is the closest to when the data will be used/accessed (same principle as initializing a variable close to where it's used). The most immediate impact is reducing the splash radius of this change to onlydynamic_forms.jsand not having to touchsession_contexts_helper.rb