diff --git a/app/views/shared/_create_account_form.html.erb b/app/views/shared/_create_account_form.html.erb index 6bdf261..ce3c2fe 100644 --- a/app/views/shared/_create_account_form.html.erb +++ b/app/views/shared/_create_account_form.html.erb @@ -16,7 +16,7 @@ <%= render partial: "shared/my_org", locals: {f: f, default_org: @default_org, orgs: Org.where("parent_id IS NULL").order("sort_name ASC, name ASC"), - allow_other_orgs: true, required: true} %> + allow_other_orgs: true, required: false} %>
diff --git a/app/views/shared/_my_org.html.erb b/app/views/shared/_my_org.html.erb index 592a778..21a3480 100644 --- a/app/views/shared/_my_org.html.erb +++ b/app/views/shared/_my_org.html.erb @@ -11,6 +11,10 @@ error: _('Please select an organisation from the list, or click the "My organisation isn\'t listed" link and enter your organisation\'s name.'), required: required} %> + + <% if allow_other_orgs %>
<%= f.hidden_field :other_org_id, value: other_org.present? ? other_org.id : '' %> diff --git a/lib/assets/javascripts/views/shared/create_account_form.js b/lib/assets/javascripts/views/shared/create_account_form.js index eeea4b9..9170e43 100644 --- a/lib/assets/javascripts/views/shared/create_account_form.js +++ b/lib/assets/javascripts/views/shared/create_account_form.js @@ -5,5 +5,18 @@ $(() => { ariatiseForm({ selector: '#create_account_form' }); togglisePasswords({ selector: '#create_account_form' }); + + $('#create_account_form').on('submit', (e) => { + // Additional validation to force the user to choose an org or type something for other + const orgId = $('[name="user[org_id]"]'); + const otherOrg = $('[name="user[other_organisation]"]'); + if (isValidText(orgId.val()) || isValidText(otherOrg.val())) { + $('#help-org').hide(); + } else { + e.preventDefault(); + $('#help-org').show(); + } + }); + initMyOrgCombobox({ selector: '#create-account-form' }); });