diff --git a/apps/dashboard/app/lib/smart_attributes/attribute_factory.rb b/apps/dashboard/app/lib/smart_attributes/attribute_factory.rb index d598d460bc..72cd0708b2 100644 --- a/apps/dashboard/app/lib/smart_attributes/attribute_factory.rb +++ b/apps/dashboard/app/lib/smart_attributes/attribute_factory.rb @@ -25,6 +25,8 @@ def build(id, opts = {}) if respond_to?(build_method) send(build_method, opts) else + # date_field will throw an error if the value is an empty string. + opts[:value] = Date.today if opts[:widget] == 'date_field' && opts[:value].to_s.empty? Attribute.new(id, opts) end end diff --git a/apps/dashboard/test/system/batch_connect_test.rb b/apps/dashboard/test/system/batch_connect_test.rb index 91210a5188..52da4c6434 100644 --- a/apps/dashboard/test/system/batch_connect_test.rb +++ b/apps/dashboard/test/system/batch_connect_test.rb @@ -1519,4 +1519,31 @@ def get_favorites end end end + + test 'date_fields correctly initialize when empty' do + Dir.mktmpdir do |dir| + "#{dir}/app".tap { |d| Dir.mkdir(d) } + SysRouter.stubs(:base_path).returns(Pathname.new(dir)) + stub_scontrol + stub_sacctmgr + stub_git("#{dir}/app") + + form = <<~HEREDOC + --- + cluster: + - owens + form: + - date + attributes: + date: + widget: 'date_field' + HEREDOC + + Pathname.new("#{dir}/app/").join('form.yml').write(form) + visit new_batch_connect_session_context_url('sys/app') + + value = find('#batch_connect_session_context_date').value + assert_equal(Date.today.to_s, value) + end + end end