-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add support for the input
tag
#4
base: master
Are you sure you want to change the base?
Add support for the input
tag
#4
Conversation
def input(record_name, method, options = {}) | ||
raise_broken_code_error | ||
InstanceTag.new(record_name, method, self).to_tag(options) | ||
# # => <input id="post_title" name="post[title]" size="30" maxlength="30" type="text" value="Hello World" /> |
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 find more value in adding the maxlength attribute as well, in addition to the size.
# # => <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> | ||
def input(record_name, method, options = {}) | ||
raise_broken_code_error | ||
InstanceTag.new(record_name, method, self).to_tag(options) |
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.
This was inspired by the deprecated class InstanceTag
and relied on methods such as to_input_field_tag
that are no longer available. Instead I'm using Tags::TextField
or similars.
|
||
def options_with_default | ||
@options.tap do |options| | ||
options["maxlength"] = DEFAULT_MAXLENGTH unless @options.key?("maxlength") |
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.
the render
methods sets the size
attribute based on the maxlength
option https://github.com/rails/rails/blob/main/actionview/lib/action_view/helpers/tags/text_field.rb#L11-L18
when :time | ||
Tags::TimeField.new(*generic_args).render | ||
when :boolean | ||
Tags::CheckBox.new(@object_name, @method, @context, "1", "0", @options).render |
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.
In my opinion, setting the maxlength attribute for a checkbox input doesn't make much sense
when :time | ||
Tags::TimeField.new(*generic_args).render | ||
when :boolean | ||
Tags::CheckBox.new(@object_name, @method, @context, "1", "0", @options).render |
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.
It makes sense for this tag to be a checkbox input instead of a select, as previously https://api.rubyonrails.org/v3.1.3/classes/ActionView/Helpers/InstanceTag.html#method-i-to_boolean_select_tag
Add support for the
input
tag for usage asinput("post", "title")
.