diff --git a/app/views/shared/_create_account_form.html.erb b/app/views/shared/_create_account_form.html.erb index 3ed5abe..1c10cb6 100644 --- a/app/views/shared/_create_account_form.html.erb +++ b/app/views/shared/_create_account_form.html.erb @@ -15,8 +15,8 @@
<%= render partial: "shared/my_org", locals: {f: f, default_org: @default_org, - orgs: Org.order("sort_name ASC, name ASC"), - allow_other_orgs: true, required: true} %> + orgs: Org.where("is_other IS NULL").order("sort_name ASC, name ASC"), + 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 375c9ef..21a3480 100644 --- a/app/views/shared/_my_org.html.erb +++ b/app/views/shared/_my_org.html.erb @@ -11,13 +11,18 @@ 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 : '' %> + <%= f.hidden_field :other_org_name, value: other_org.present? ? other_org.name : '' %> <%= _('My organisation isn\'t listed.') %>
- <%= f.text_field :other_organisation, autocomplete: "off", class: "form-control hide other-org", + <%= f.text_field :other_organisation, autocomplete: "off", class: "form-control hide other-org", placeholder: _('Please enter the name of your organisation'), "aria-label": "other_organisation" %> <% end %> diff --git a/lib/assets/javascripts/views/shared/create_account_form.js b/lib/assets/javascripts/views/shared/create_account_form.js index a423660..fe57717 100644 --- a/lib/assets/javascripts/views/shared/create_account_form.js +++ b/lib/assets/javascripts/views/shared/create_account_form.js @@ -1,10 +1,20 @@ import ariatiseForm from '../../utils/ariatiseForm'; import { togglisePasswords } from '../../utils/passwordHelper'; -import initMyOrgCombobox from '../shared/my_org'; +import validateOrgSelection from '../shared/my_org'; +import { isValidText } from '../../utils/isValidInputType'; $(() => { const options = { selector: '#create-account-form' }; - initMyOrgCombobox(options); ariatiseForm(options); togglisePasswords(options); + + $('#create_account_form').on('submit', (e) => { + // Additional validation to force the user to choose an org or type something for other + if (validateOrgSelection()) { + $('#help-org').hide(); + } else { + e.preventDefault(); + $('#help-org').show(); + } + }); }); diff --git a/lib/assets/javascripts/views/shared/my_org.js b/lib/assets/javascripts/views/shared/my_org.js index a38eb26..eb85336 100644 --- a/lib/assets/javascripts/views/shared/my_org.js +++ b/lib/assets/javascripts/views/shared/my_org.js @@ -8,9 +8,11 @@ if (isObject(div)) { const combo = div.find('input.js-combobox'); const id = div.find('input.org-id'); + const name = div.find('input[name="user[org_name]"]'); const text = div.find('input.other-org'); const link = div.find('a.other-org-link'); const otherOrg = div.find('input[name="user[other_org_id]"]'); + const otherOrgName = div.find('input[name="user[other_org_name]"]'); const toggleInputs = (showCombo) => { if (showCombo) { @@ -36,6 +38,7 @@ text.blur(() => { if (isObject(id)) { id.val(text.val().length > 0 ? otherOrg.val() : ''); + name.val(text.val().length > 0 ? otherOrgName.val() : ''); } }); @@ -48,3 +51,10 @@ } } }; + +export const validateOrgSelection = () => { + const orgId = $('[name="user[org_id]"]'); + const otherOrg = $('[name="user[other_organisation]"]'); + + return isValidText(orgId.val()) || isValidText(otherOrg.val()); +};