Skip to content

Commit 3fb9129

Browse files
author
John Pinto
committed
Updated select input in create form.
If there is one org then it it automatically selected. If there is no org returned we do not show prompt. If there is more than one org we have propmt with text "Select an organisation".
1 parent 942fc7f commit 3fb9129

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

app/javascript/src/shared/createAccountForm.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ $(() => {
1616
let debounceTimer = null;
1717

1818
// Handle email input changes
19-
emailField.addEventListener('input', function() {
19+
emailField.addEventListener('input', function () {
2020
const email = this.value;
2121

2222
if (email && email.includes('@')) {
2323
if (email !== currentEmail) {
2424
currentEmail = email;
25-
25+
2626
// Clear previous timer
2727
if (debounceTimer) {
2828
clearTimeout(debounceTimer);
@@ -56,23 +56,29 @@ $(() => {
5656
// Clear existing options
5757
orgSelect.innerHTML = '';
5858

59-
// Add prompt option
60-
const promptOption = document.createElement('option');
61-
promptOption.value = '';
62-
promptOption.textContent = 'Select an organisation';
63-
orgSelect.appendChild(promptOption);
59+
if (orgs.length > 1) {
60+
// Add prompt option
61+
const promptOption = document.createElement('option');
62+
promptOption.value = '';
63+
promptOption.textContent = 'Select an organisation';
64+
orgSelect.appendChild(promptOption);
65+
}
6466

6567
// Add organization options
66-
orgs.forEach(function(org) {
68+
orgs.forEach(function (org) {
6769
const option = document.createElement('option');
6870
option.value = org.id || org.ror_id;
6971
option.textContent = org.org_name;
7072
orgSelect.appendChild(option);
7173
});
74+
// Only select option if only one
75+
if (orgs.length === 1) {
76+
orgSelect.selectedIndex = 0;
77+
}
7278
}
7379

7480
function resetOrgSelect() {
75-
orgSelect.innerHTML = '<option value="">Select an organisation</option>';
81+
orgSelect.innerHTML = '';
7682
}
7783
});
7884

app/views/shared/_create_account_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<div class="form rm-form-row">
2424
<div class="col-12" id="create-account-org-controls">
2525
<%= f.label(:org_name, _('Organisation'), class: "form-label") %>
26-
<%= f.select(:org_id, [], { prompt: _('Select an organisation') }, { class: "form-control" }) %>
26+
<%= f.select(:org_id, [], { prompt: '' }, { class: "form-control" }) %>
2727
</div>
2828
</div>
2929

0 commit comments

Comments
 (0)