Replies: 3 comments 10 replies
-
The |
Beta Was this translation helpful? Give feedback.
-
I've noticed the same thing when I styled my forms with custom CSS according to the given design. |
Beta Was this translation helpful? Give feedback.
-
@janko @v-kolesnikov What do you think of this approach? This allows turning it off easily. I'm open to other approaches if you have ideas in this area. diff --git a/lib/sequel/plugins/forme.rb b/lib/sequel/plugins/forme.rb
index 2f07b48..262b5ed 100644
--- a/lib/sequel/plugins/forme.rb
+++ b/lib/sequel/plugins/forme.rb
@@ -207,7 +207,7 @@ module Sequel # :nodoc:
# 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]
+ opts[:label] = [opts[:label], form._tag(:abbr, {:title=>'required'}, '*')] if opts[:label] && opts[:required] && obj.forme_use_required_abbr?
end
# Update the attributes and options for any recognized validations
@@ -492,6 +492,11 @@ module Sequel # :nodoc:
'post'
end
+ # Whether to set an abbr tag in labels for required inputs.
+ def forme_use_required_abbr?
+ true
+ end
+
# Use the underscored model name as the default namespace.
def forme_namespace
model.send(:underscore, model.name)
diff --git a/spec/sequel_plugin_spec.rb b/spec/sequel_plugin_spec.rb
index e1aa464..24b8d82 100644
--- a/spec/sequel_plugin_spec.rb
+++ b/spec/sequel_plugin_spec.rb
@@ -133,6 +133,11 @@ describe "Forme Sequel::Model forms" do
@b.input(:name, :required=>true, :label=>nil).must_equal '<input id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/>'
end
+ it "should not add required * in label if obj.forme_use_required_abbr? is false" do
+ 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 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>' |
Beta Was this translation helpful? Give feedback.
-
I'm using Forme with Roda and Sequel, and Forme is automatically appending the
*
to the form label on fields whose columns have aNOT NULL
constraint. However, I would prefer not to display it, at least not by default. Is there a way to do that? I know I can setrequired: false
on the input, but so far I didn't find a way to set it as default.Beta Was this translation helpful? Give feedback.
All reactions