Skip to content

Commit

Permalink
Support Sequel::Model#forme_required_abbr_title to control the conten…
Browse files Browse the repository at this point in the history
…t of the title attribute for abbr tags
  • Loading branch information
jeremyevans committed Sep 14, 2024
1 parent dfd2cd9 commit 4b012b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Support Sequel::Model#forme_required_abbr_title to control the content of the title attribute for abbr tags (jeremyevans)

* Add Serializer#self_closing_tag? private method for easier overriding in subclasses (jeremyevans)

=== 2.6.0 (2024-06-18)
Expand Down
7 changes: 6 additions & 1 deletion lib/sequel/plugins/forme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def handle_errors(f)
# is required.
def handle_label(f)
opts[:label] = humanize(field) unless opts.has_key?(:label)
opts[:label] = [opts[:label], form._tag(:abbr, {:title=>'required'}, '*')] if opts[:label] && opts[:required] && obj.forme_use_required_abbr?
opts[:label] = [opts[:label], form._tag(:abbr, {:title=>obj.forme_required_abbr_title}, '*')] if opts[:label] && opts[:required] && obj.forme_use_required_abbr?
end

# Update the attributes and options for any recognized validations
Expand Down Expand Up @@ -508,6 +508,11 @@ def forme_default_request_method
'post'
end

# The content of the title attribute of the abbr tag included in labels that are required.
def forme_required_abbr_title
'required'
end

# Whether to set an abbr tag in labels for required inputs.
def forme_use_required_abbr?
true
Expand Down
5 changes: 5 additions & 0 deletions spec/sequel_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ def @ab.forme_use_required_abbr?; false end
@b.input(:name, :required=>true).must_equal '<label>Name: <input id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></label>'
end

it "should use obj.forme_required_abbr_title to set title attribute of abbr tag" do
def @ab.forme_required_abbr_title; "foo" end
@b.input(:name, :required=>true).must_equal '<label>Name<abbr title="foo">*</abbr>: <input id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></label>'
end

it "should include required wrapper class if required" do
f = Forme::Form.new(@ab, :wrapper=>:li)
f.input(:name, :required=>true).must_equal '<li class="string required"><label>Name<abbr title="required">*</abbr>: <input id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></label></li>'
Expand Down

0 comments on commit 4b012b9

Please sign in to comment.