-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding javascript validation of the description
Moving required field validation to a Vite class Adding a Required field partial to make the javascript more concise
- Loading branch information
1 parent
963609e
commit fec775b
Showing
9 changed files
with
120 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
export default class EditRequiredFields { | ||
attach_validations() { | ||
// Client side validations before allowing user to create the dataset. | ||
$('#btn-create-new').on('click', this.validate_required.bind(this)); | ||
if ($('#description') !== undefined) { | ||
$('#btn-submit').on('click', this.validate_required_step2.bind(this)); | ||
} | ||
} | ||
|
||
validate_required() { | ||
const title = $('#title_main').val() || ''; | ||
let status = true; | ||
|
||
$('#title-required-message').addClass('hidden'); | ||
$('#creators-required-message').addClass('hidden'); | ||
|
||
if (!this.hasCreators()) { | ||
$(`#${this.findEmptyCreator()}`).focus(); | ||
$('#creators-required-message').removeClass('hidden'); | ||
status = false; | ||
} | ||
|
||
if (title.trim() === '') { | ||
$('#title_main').focus(); | ||
$('#title-required-message').removeClass('hidden'); | ||
status = false; | ||
} | ||
|
||
return status; | ||
|
||
} | ||
|
||
validate_required_step2() { | ||
const description = $('#description').val() || ''; | ||
let status = this.validate_required(); | ||
$('#description-required-message').addClass('hidden'); | ||
|
||
if (description.trim() === '') { | ||
if (status) | ||
$('#description').focus(); | ||
$('#description-required-message').removeClass('hidden'); | ||
status = false; | ||
} | ||
return status | ||
} | ||
|
||
|
||
|
||
// Returns true if there is at least one creator with information | ||
hasCreators() { | ||
let i; | ||
const rows = $('.creators-table-row'); | ||
for (i = 0; i < rows.length; i += 1) { | ||
if (!this.isEmptyRow(rows[i].id)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
// Returns true if the "user entered" textboxes for the row are empty. | ||
isEmptyRow(rowId) { | ||
let i; let textboxId; let value; | ||
const $textboxes = $(`#${rowId} > td > input`); | ||
for (i = 0; i < $textboxes.length; i += 1) { | ||
textboxId = $textboxes[i].id; | ||
if (textboxId.startsWith('orcid_') || textboxId.startsWith('given_name_') || textboxId.startsWith('family_name_')) { | ||
value = $(`#${textboxId}`).val().trim(); | ||
if (value !== '') { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
// Returns the ID of the first row that has an empty creator (if any) | ||
findEmptyCreator() { | ||
let i; | ||
const rows = $('.creators-table-row'); | ||
for (i = 0; i < rows.length; i += 1) { | ||
if (this.isEmptyRow(rows[i].id)) { | ||
return rows[i].id; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<% field_error ||= "Must provide a #{name}" %> | ||
<details> | ||
<summary> | ||
<%= display_name %><span class="required-field" title="<%= display_name %> for your submission must be indicated">*</span> | ||
<span id="<%= name %>-required-message" class="hidden"> | ||
<i class="bi bi-exclamation-diamond-fill required-field"></i> <%= field_error %> | ||
</span> | ||
</summary> | ||
<%= field_detail %> | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters