Skip to content

Commit 2e6bd38

Browse files
carolyncoleJaymeeH
andauthored
clear the error message when a data sponsor or manager has been selected (#2246)
Also move lux initialization to a higher div so that the user select components are all in one lux session, which gives them different ids fixes #2237 Co-authored-by: Jaymee Hyppolite <[email protected]>
1 parent 6822aeb commit 2e6bd38

File tree

11 files changed

+39
-21
lines changed

11 files changed

+39
-21
lines changed

app/assets/stylesheets/_wizard.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
}
154154

155155
.modal-content .text-input,
156-
.lux {
156+
.lux-field {
157157
width: 100%;
158158
}
159159
}

app/javascript/entrypoints/application.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,18 @@ async function searchUsers(query) {
4747
return [];
4848
}
4949

50+
function clearUserError(event, component) {
51+
document.getElementById(component).innerHTML = '';
52+
}
53+
5054
// If you are not running a full Vue application, just embedding the component into a static HTML,
5155
// ruby web app, or similar: one way to bind your logic to the async-load-items-function prop is
5256
// to add it to the vue application's globalProperties.
5357
const createMyApp = () => {
5458
const myapp = createApp(app);
5559
myapp.config.globalProperties.searchUsers = (query) => searchUsers(query);
60+
myapp.config.globalProperties.clearUserError = (event, component) =>
61+
clearUserError(event, component);
5662
return myapp;
5763
};
5864

app/javascript/entrypoints/validation.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ export function validationClear() {
33
$('.form-field input').on('keyup', (event) => {
44
const element = event.currentTarget;
55
const errorElement = element.parentNode.querySelector('.input-error');
6-
if (element.value.length > 0 && errorElement.innerText === 'cannot be empty') {
6+
if (
7+
element.value.length > 0 &&
8+
errorElement &&
9+
errorElement.innerText === 'cannot be empty'
10+
) {
711
errorElement.innerHTML = '';
812
}
913
});

app/views/new_project_wizard/_form_user_input.html.erb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33
<div class="horizontal-frame">
44
<div class="vertical-frame">
55

6-
<div class="lux field" id="<%= field_name %>_input">
6+
<div class="lux-field field" id="<%= field_name %>_input">
77
<lux-input-async-select
88
label="<%= field_name.titleize %>"
99
hide-label="true"
1010
placeholder="Select a <%= field_name.titleize %>"
1111
:async-load-items-function="searchUsers"
12+
@selected="clearUserError($event,'data-user-error-<%= field_name %>')"
1213
id="data-user-select-<%= field_name %>"
1314
:default-value="<%= {label: field_value, id: field_id_value}.to_json %>"
1415
>
1516
<template v-slot:hidden-input="{ selectedItem }">
17+
<input type="hidden" class="selected_user_label" :value="selectedItem.label"></input>
1618
<input type="hidden" name="request[<%= field_name %>]" class="selected_user" :value="selectedItem.id"></input>
1719
</template>
1820
</lux-input-async-select>
1921
</div>
20-
<div class="input-error">
22+
<div class="input-error" id="data-user-error-<%= field_name %>">
2123
<%= field_error %>
2224
</div>
2325
</div>

app/views/new_project_wizard/_form_user_roles_input.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<div class="text-input">
4343
<div class="horizontal-frame">
4444
<div class="vertical-frame">
45-
<div class="lux field data-users">
45+
<div class="lux-field field data-users">
4646
<lux-input-multiselect
4747
label=""
4848
selected-items-label=""

app/views/new_project_wizard/_review_and_submit_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<%= render partial: "/new_project_wizard/form_department_input", locals: {departments: @request_model.departments || [], department_error: @request_model.errors[:departments].join(", ") } %>
1313
</div>
1414
<div class="section-line"></div>
15-
<div class="section">
15+
<div class="section lux">
1616
<div class="section-title">
1717
<div class="section-frame">
1818
Roles and People

app/views/new_project_wizard/roles_and_people.html.erb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
<% content_for :form_title, "Roles and People" %>
33
<% content_for :form_description, "Assign roles for your project." %>
44

5-
<%= render partial: "/new_project_wizard/form_data_sponsor_input",
6-
locals: {data_sponsor: @request_model.data_sponsor || "", data_sponsor_name: @request_model.data_sponsor_name, data_sponsor_error: @request_model.errors[:data_sponsor].join(", ") } %>
7-
<%= render partial: "/new_project_wizard/form_data_manager_input",
8-
locals: {data_manager: @request_model.data_manager || "", data_manager_name: @request_model.data_manager_name, data_manager_error: @request_model.errors[:data_manager].join(", ") } %>
9-
<%= render partial: "/new_project_wizard/form_user_roles_input", locals: {user_roles: @request_model.user_roles || [], user_roles_error: "" } %>
5+
<div class="lux">
6+
<%= render partial: "/new_project_wizard/form_data_sponsor_input",
7+
locals: {data_sponsor: @request_model.data_sponsor || "", data_sponsor_name: @request_model.data_sponsor_name, data_sponsor_error: @request_model.errors[:data_sponsor].join(", ") } %>
8+
<%= render partial: "/new_project_wizard/form_data_manager_input",
9+
locals: {data_manager: @request_model.data_manager || "", data_manager_name: @request_model.data_manager_name, data_manager_error: @request_model.errors[:data_manager].join(", ") } %>
10+
<%= render partial: "/new_project_wizard/form_user_roles_input", locals: {user_roles: @request_model.user_roles || [], user_roles_error: "" } %>
1011

11-
<input id="users_lookup_url" type="hidden" value="<%= users_lookup_url %>"/>
12+
<input id="users_lookup_url" type="hidden" value="<%= users_lookup_url %>"/>
13+
</div>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"browserslist": "^4.21.5",
3030
"datatables": "^1.10.18",
3131
"jquery": "^3.6.3",
32-
"lux-design-system": "^7.2.1",
32+
"lux-design-system": "^7.3.0",
3333
"nanoid": ">=3.3.8",
3434
"vite-plugin-rails": "^0.5.0",
3535
"vue": "^3.5.22",

spec/support/select_user.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
def select_user(user, field, hidden_field)
33
user_str = user.display_name_safe
44
within("##{field}_input") do
5-
page.find(".field.lux input").fill_in with: user.uid
5+
page.find(".field.lux-field input").fill_in with: user.uid
66
expect(page).to have_content user_str
77
find(".lux-autocomplete-result").click
88

@@ -15,7 +15,7 @@ def select_data_user(user, user_list)
1515
user_str = user.display_name_safe
1616

1717
within(".user-role") do
18-
page.find(".data-users.lux input").fill_in with: user.uid
18+
page.find(".data-users.lux-field input").fill_in with: user.uid
1919
expect(page).to have_content user_str
2020
find(".lux-autocomplete-result").click
2121

@@ -25,6 +25,6 @@ def select_data_user(user, user_list)
2525
expect(page).to have_field("all_selected", type: :hidden, with: user_list.to_json)
2626

2727
# the javascript cleared the find to get ready for the next search
28-
expect(page.find(".data-users.lux input").value).to eq("")
28+
expect(page.find(".data-users.lux-field input").value).to eq("")
2929
end
3030
end

spec/system/request_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@
266266
expect(page).to have_content("Review")
267267
within(".project-title") do
268268
expect(page).to have_content("cannot be empty")
269+
fill_in :project_title, with: "A basic Project"
270+
expect(page).not_to have_content("cannot be empty")
269271
end
270272
within(".project-description") do
271273
expect(page).to have_content("cannot be empty")
@@ -281,6 +283,8 @@
281283
end
282284
within(".data-sponsor") do
283285
expect(page).to have_content("cannot be empty")
286+
select_user(current_user, "data_sponsor", "request[data_sponsor]")
287+
expect(page).not_to have_content("cannot be empty")
284288
end
285289
within(".project-folder") do
286290
expect(page).to have_content("cannot be empty")

0 commit comments

Comments
 (0)