Skip to content

Commit

Permalink
Issue webcompat#1167. Refactor makeInvalid and add support for browse…
Browse files Browse the repository at this point in the history
…r and os fields.
  • Loading branch information
Mike Taylor authored and deepthivenkat committed Oct 19, 2016
1 parent 3f63808 commit e3f3cc7
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions webcompat/static/js/lib/bugform.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

function BugForm() {
this.form = $('#js-ReportForm form');
this.descField = $('#description');
this.submitButtons = $('#js-ReportForm .js-Button');
this.loadingIndicator = $('.js-Loader');
this.reportButton = $('#js-ReportBug');
Expand Down Expand Up @@ -50,6 +49,7 @@ function BugForm() {
this.problemType = this.inputs.problem_type.el;
this.uploadField = this.inputs.image.el;
this.urlField = this.inputs.url.el;
this.descField = $('#description');

this.init = function() {
this.checkParams();
Expand Down Expand Up @@ -250,29 +250,34 @@ function BugForm() {
.removeClass('is-validated js-no-error')
.addClass('is-error js-form-error');

if (id === 'url') {
inlineHelp.insertAfter('label[for=' + id + ']');
}

if (id === 'problem_type') {
inlineHelp.appendTo('.wc-Form-information');
}

if (id === 'image') {
// hide the error in case we already saw one
$('.wc-Form-helpMessage--imageUpload').remove();

inlineHelp.removeClass('wc-Form-helpMessage')
.addClass('wc-Form-helpMessage--imageUpload')
.insertAfter('.js-image-upload-label');

$('.wc-UploadForm-label').hide();
// "reset" the form field, because the file would get rejected
// from the server anyways.
this.uploadField.val(this.uploadField.get(0).defaultValue);
// return early because we just cleared out the input.
// someone might decide to just not select an image.
return;
switch (id) {
case 'os':
case 'browser':
// remove error classes, because these inputs are optional
this.inputs[id].el.parents('.js-Form-group')
.removeClass('is-error js-form-error');
break;
case 'url':
inlineHelp.insertAfter('label[for=' + id + ']');
break;
case 'problem_type':
inlineHelp.appendTo('.wc-Form-information');
break;
case 'image':
// hide the error in case we already saw one
$('.wc-Form-helpMessage--imageUpload').remove();

inlineHelp.removeClass('wc-Form-helpMessage')
.addClass('wc-Form-helpMessage--imageUpload')
.insertAfter('.js-image-upload-label');

$('.wc-UploadForm-label').hide();
// "reset" the form field, because the file would get rejected
// from the server anyways.
this.uploadField.val(this.uploadField.get(0).defaultValue);
// return early because we just cleared out the input.
// someone might decide to just not select an image.
return;
}

this.disableSubmits();
Expand Down

0 comments on commit e3f3cc7

Please sign in to comment.