-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
date_select
helper method extension
#13591
Changes from all commits
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 |
---|---|---|
|
@@ -817,19 +817,25 @@ def select_month | |
end | ||
|
||
def select_year | ||
middle_years = [Date.today.year] | ||
|
||
if !@datetime || @datetime == 0 | ||
val = '1' | ||
middle_year = Date.today.year | ||
else | ||
val = middle_year = year | ||
val = year | ||
if year.abs === Float::INFINITY | ||
middle_years = [year] | ||
else | ||
middle_years.push(year) | ||
end | ||
end | ||
|
||
if @options[:use_hidden] || @options[:discard_year] | ||
build_hidden(:year, val) | ||
else | ||
options = {} | ||
options[:start] = @options[:start_year] || middle_year - 5 | ||
options[:end] = @options[:end_year] || middle_year + 5 | ||
options[:start] = @options[:start_year] || middle_years.min - 5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this min case? Lets take the simpler and safer path and change this code to take in consideration only the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah this is more safer 👍 I will change it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rafaelfranca But suppose a user selected There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How users will select 1905 if it is not disponible in the select box? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the current system, the start and end limits are also dependent on the selected value. Am I wrong in this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, you are right. This is exactly what is causing confusion. If we are going to keep the implementation dependent on the selected value I prefer to keep it as it is since it is easier to explain than:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rafaelfranca But there is an issue in that case, suppose we choose There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'm aware of this issue. What I'm trying to explain here is: we will not solve this problem adding more magic in this method. Adding more magic in the method will only add more confusion to users. After this "Why is the select taking in consideration the selected value?" is not a simple answer anymore. For the issue you mentioned above I'd say, define the I want to go simpler, or we change this behavior to do less magic or we keep it as it is. More magic is not an option here since it will only add more confusion. Right now, I'm inclined to keep it as it is, since it will not require any change in the people application and the current behavior is documented. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll think better about this and do some tests with this branch. Thank you for working on this ❤️ |
||
options[:end] = @options[:end_year] || middle_years.max + 5 | ||
options[:step] = options[:start] < options[:end] ? 1 : -1 | ||
options[:leading_zeros] = false | ||
options[:max_years_allowed] = @options[:max_years_allowed] || 1000 | ||
|
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.
Why this infinity case?
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.
Checkout this test case, this is for infinity.
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.
Ok. but why it is needed only now?