Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

okcomputer93
Copy link

Add support for the input tag for usage as input("post", "title").

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" />
Copy link
Author

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)
Copy link
Author

@okcomputer93 okcomputer93 Apr 2, 2024

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.

@okcomputer93 okcomputer93 marked this pull request as draft April 2, 2024 17:07

def options_with_default
@options.tap do |options|
options["maxlength"] = DEFAULT_MAXLENGTH unless @options.key?("maxlength")
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

@okcomputer93 okcomputer93 marked this pull request as ready for review April 3, 2024 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant