Skip to content

Commit

Permalink
Display missing value code validation errors
Browse files Browse the repository at this point in the history
Issue #612
  • Loading branch information
robyngit committed Jul 21, 2023
1 parent 8d4bfc0 commit 27a77f0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
34 changes: 18 additions & 16 deletions src/js/models/metadata/eml211/EMLAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,25 +481,27 @@ define(["jquery", "underscore", "backbone", "uuid",
errors.measurementScale = "Choose a measurement scale category for this attribute.";
}
else{
var measurementScaleIsValid = measurementScaleModel.isValid();

// If there is a measurement scale model and it is valid and there are no other
// errors, then trigger this model as valid and exit.
if( measurementScaleIsValid && !Object.keys(errors).length ){

this.trigger("valid", this);
return;

}
else if( !measurementScaleIsValid ){
if( !measurementScaleModel.isValid() ){
errors.measurementScale = "More information is needed.";
}
}

//If there is at least one error, then return the errors object
if(Object.keys(errors).length)
return errors;
}

// Validate the missing value codes
var missingValueCodesErrors = this.get("missingValueCodes")?.validate();
if (missingValueCodesErrors) {
// Just display the first error message
errors.missingValueCodes = Object.values(missingValueCodesErrors)[0]
}

// If there is a measurement scale model and it is valid and there are no other
// errors, then trigger this model as valid and exit.
if (!Object.keys(errors).length) {
this.trigger("valid", this);
return;
} else {
//If there is at least one error, then return the errors object
return errors;
}
},

/*
Expand Down
2 changes: 1 addition & 1 deletion src/js/views/metadata/EML211MissingValueView.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define([
* collection, the view will also provide a button to remove the model from
* the collection.
* @classcategory Views/Metadata
* @screenshot views/metadata/EMLMissingValueView.png // <- TODO
* @screenshot views/metadata/EMLMissingValueView.png
* @extends Backbone.View
* @since x.x.x
*/
Expand Down
4 changes: 2 additions & 2 deletions src/js/views/metadata/EML211MissingValuesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ define([
* "Remove" button next to the code. A new row of inputs will automatically be
* added to the view when the user starts typing in the last row of inputs.
* @classcategory Views/Metadata
* @screenshot views/metadata/EMLMissingValuesView.png // <- TODO
* @screenshot views/metadata/EMLMissingValuesView.png
* @extends Backbone.View
* @since x.x.x
*/
Expand Down Expand Up @@ -101,6 +101,7 @@ define([
}
this.setListeners();
this.el.innerHTML = "";
this.el.setAttribute("data-category", "missingValueCodes");
this.renderText();
this.renderRows();

Expand All @@ -125,7 +126,6 @@ define([

this.notification = document.createElement("p");
this.notification.classList.add(this.classes.notification);
this.notification.setAttribute("data-category", "missingValueCodes");
this.el.appendChild(this.notification);

},
Expand Down

0 comments on commit 27a77f0

Please sign in to comment.