UX: make name optional for confirmation user field (#7149)

UX: make name optional for confirmation user field (#7149)

diff --git a/app/assets/javascripts/discourse/templates/components/user-fields/confirm.hbs b/app/assets/javascripts/discourse/templates/components/user-fields/confirm.hbs
index 18896a4..f3bcf80 100644
--- a/app/assets/javascripts/discourse/templates/components/user-fields/confirm.hbs
+++ b/app/assets/javascripts/discourse/templates/components/user-fields/confirm.hbs
@@ -1,5 +1,14 @@
-<label class="control-label" for="{{concat 'user-' elementId}}">{{{field.name}}}   {{#if field.required}}<span class='required'>*</span>{{/if}}
-</label>
+{{#if field.name}}
+  <label class="control-label" for="{{concat 'user-' elementId}}">
+    {{{field.name}}}   {{#if field.required}}<span class='required'>*</span>{{/if}}
+  </label>
+{{/if}}
+
 <div class='controls'>
-  <label class="control-label checkbox-label">{{input id=(concat 'user-' elementId) checked=value type="checkbox"}} <span>{{{field.description}}}</span></label>
+  <label class="control-label checkbox-label">
+    {{input id=(concat 'user-' elementId) checked=value type="checkbox"}}
+    <span>
+      {{{field.description}}}   {{#unless field.name}}{{#if field.required}}<span class='required'>*</span>{{/if}}{{/unless}}
+    </span>
+  </label>
 </div>
diff --git a/app/models/user_field.rb b/app/models/user_field.rb
index 27789fb..65dcc62 100644
--- a/app/models/user_field.rb
+++ b/app/models/user_field.rb
@@ -2,7 +2,8 @@ class UserField < ActiveRecord::Base
 
   include AnonCacheInvalidator
 
-  validates_presence_of :name, :description, :field_type
+  validates_presence_of :description, :field_type
+  validates_presence_of :name, unless: -> { field_type == "confirm" }
   has_many :user_field_options, dependent: :destroy
   accepts_nested_attributes_for :user_field_options
 
diff --git a/spec/models/user_field_spec.rb b/spec/models/user_field_spec.rb
new file mode 100644
index 0000000..f75dafe
--- /dev/null
+++ b/spec/models/user_field_spec.rb
@@ -0,0 +1,13 @@
+require 'rails_helper'
+
+describe UserField do
+  describe "doesn't validate presence of name if field type is 'confirm'" do
+    subject { described_class.new(field_type: 'confirm') }
+    it { is_expected.not_to validate_presence_of :name }
+  end
+
+  describe "validates presence of name for other field types" do
+    subject { described_class.new(field_type: 'dropdown') }
+    it { is_expected.to validate_presence_of :name }
+  end
+end

GitHub sha: 65f3ed06