Skip to content

Commit e3f3cc7

Browse files
Mike Taylordeepthivenkat
Mike Taylor
authored andcommitted
Issue webcompat#1167. Refactor makeInvalid and add support for browser and os fields.
1 parent 3f63808 commit e3f3cc7

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

webcompat/static/js/lib/bugform.js

+29-24
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
function BugForm() {
66
this.form = $('#js-ReportForm form');
7-
this.descField = $('#description');
87
this.submitButtons = $('#js-ReportForm .js-Button');
98
this.loadingIndicator = $('.js-Loader');
109
this.reportButton = $('#js-ReportBug');
@@ -50,6 +49,7 @@ function BugForm() {
5049
this.problemType = this.inputs.problem_type.el;
5150
this.uploadField = this.inputs.image.el;
5251
this.urlField = this.inputs.url.el;
52+
this.descField = $('#description');
5353

5454
this.init = function() {
5555
this.checkParams();
@@ -250,29 +250,34 @@ function BugForm() {
250250
.removeClass('is-validated js-no-error')
251251
.addClass('is-error js-form-error');
252252

253-
if (id === 'url') {
254-
inlineHelp.insertAfter('label[for=' + id + ']');
255-
}
256-
257-
if (id === 'problem_type') {
258-
inlineHelp.appendTo('.wc-Form-information');
259-
}
260-
261-
if (id === 'image') {
262-
// hide the error in case we already saw one
263-
$('.wc-Form-helpMessage--imageUpload').remove();
264-
265-
inlineHelp.removeClass('wc-Form-helpMessage')
266-
.addClass('wc-Form-helpMessage--imageUpload')
267-
.insertAfter('.js-image-upload-label');
268-
269-
$('.wc-UploadForm-label').hide();
270-
// "reset" the form field, because the file would get rejected
271-
// from the server anyways.
272-
this.uploadField.val(this.uploadField.get(0).defaultValue);
273-
// return early because we just cleared out the input.
274-
// someone might decide to just not select an image.
275-
return;
253+
switch (id) {
254+
case 'os':
255+
case 'browser':
256+
// remove error classes, because these inputs are optional
257+
this.inputs[id].el.parents('.js-Form-group')
258+
.removeClass('is-error js-form-error');
259+
break;
260+
case 'url':
261+
inlineHelp.insertAfter('label[for=' + id + ']');
262+
break;
263+
case 'problem_type':
264+
inlineHelp.appendTo('.wc-Form-information');
265+
break;
266+
case 'image':
267+
// hide the error in case we already saw one
268+
$('.wc-Form-helpMessage--imageUpload').remove();
269+
270+
inlineHelp.removeClass('wc-Form-helpMessage')
271+
.addClass('wc-Form-helpMessage--imageUpload')
272+
.insertAfter('.js-image-upload-label');
273+
274+
$('.wc-UploadForm-label').hide();
275+
// "reset" the form field, because the file would get rejected
276+
// from the server anyways.
277+
this.uploadField.val(this.uploadField.get(0).defaultValue);
278+
// return early because we just cleared out the input.
279+
// someone might decide to just not select an image.
280+
return;
276281
}
277282

278283
this.disableSubmits();

0 commit comments

Comments
 (0)