Skip to content

Commit

Permalink
Issue #2725: Run validation in "silent" mode on page refresh or when …
Browse files Browse the repository at this point in the history
…coming from the report site issue extension
  • Loading branch information
ksy36 committed May 31, 2019
1 parent 508269a commit 196b5c3
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions webcompat/static/js/lib/bugform.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,25 @@ BugForm.prototype.determineValidityFunction = function(func, field, silent) {
return silent ? "makeInvalidSilent" : "makeInvalid";
};

BugForm.prototype.checkProblemTypeValidity = function() {
BugForm.prototype.checkProblemTypeValidity = function(silent) {
var func = this.determineValidityFunction(
this.validation.isProblemTypeValid,
this.problemType
this.problemType,
silent
);
this[func]("problem_category");
};

BugForm.prototype.checkImageTypeValidity = function(event) {
BugForm.prototype.checkImageTypeValidity = function(event, silent) {
// Bail if there's no image.
if (!this.uploadField.val()) {
return;
}

var func = this.determineValidityFunction(
this.validation.isImageTypeValid,
this.uploadField
this.uploadField,
silent
);
this[func]("image");

Expand Down Expand Up @@ -379,10 +381,11 @@ BugForm.prototype.checkOptionalNonEmpty = function(field) {
};

/* Check to see if the GitHub username has the right syntax.*/
BugForm.prototype.checkGitHubUsername = function() {
BugForm.prototype.checkGitHubUsername = function(event, silent) {
var func = this.determineValidityFunction(
this.validation.isGithubUserNameValid,
this.contactField
this.contactField,
silent
);
this[func]("contact");
};
Expand All @@ -391,12 +394,12 @@ BugForm.prototype.onSubmitAttempt = function() {
this.performChecks();
};

BugForm.prototype.performChecks = function() {
this.checkURLValidity();
this.checkDescriptionValidity();
this.checkProblemTypeValidity();
this.checkImageTypeValidity();
this.checkGitHubUsername();
BugForm.prototype.performChecks = function(isSilent) {
this.checkURLValidity(isSilent);
this.checkDescriptionValidity(isSilent);
this.checkProblemTypeValidity(isSilent);
this.checkImageTypeValidity(null, isSilent);
this.checkGitHubUsername(null, isSilent);
};

BugForm.prototype.checkForm = function() {
Expand All @@ -410,7 +413,7 @@ BugForm.prototype.checkForm = function() {
];
if (_.some(inputs, Boolean)) {
// then, check validity
this.performChecks();
this.performChecks(true);
// and open the form, if it's not already open
if (!this.reportButton.hasClass("is-open")) {
this.reportButton.click();
Expand Down

0 comments on commit 196b5c3

Please sign in to comment.