Skip to content

Commit c533ecf

Browse files
Mike Taylordeepthivenkat
Mike Taylor
authored andcommitted
Issue webcompat#1167. Remove img_too_big concept; add altHelpText to image
It was kind of gross (added an error type to a collection of inputs).
1 parent d01e576 commit c533ecf

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

webcompat/static/js/lib/bugform.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ function BugForm() {
3131
// image should be valid by default because it's optional
3232
'valid': true,
3333
'helpText': 'Image must be one of the following: jpg, png, gif, or bmp.',
34-
},
35-
'img_too_big': {
36-
'el': $('#image'),
37-
// image should be valid by default because it's optional
38-
'valid': true,
39-
'helpText': 'Please choose a smaller image (< 4MB)'
34+
'altHelpText': 'Please choose a smaller image (< 4MB)'
4035
},
4136
'browser': {
4237
'el': $('#browser'),
@@ -118,7 +113,7 @@ function BugForm() {
118113
// The limit is 4MB (which is crazy big!), so let the user know if their
119114
// file is unreasonably large at this point (after 1 round of downsampling)
120115
if (this.screenshotData > this.UPLOAD_LIMIT) {
121-
this.makeInvalid('img_too_big');
116+
this.makeInvalid('image', {altHelp: true});
122117
return;
123118
}
124119

@@ -220,15 +215,18 @@ function BugForm() {
220215
}
221216
};
222217

223-
this.makeInvalid = function(id) {
218+
/* makeInvalid can take an {altHelp: true} options argument to select
219+
alternate helpText to display */
220+
this.makeInvalid = function(id, opts) {
224221
// Early return if inline help is already in place.
225222
if (this.inputs[id].valid === false) {
226223
return;
227224
}
228225

229226
var inlineHelp = $('<span></span>', {
230227
'class': 'wc-Form-helpMessage',
231-
'text': this.inputs[id].helpText
228+
'text': opts && opts.altHelp ? this.inputs[id].altHelpText :
229+
this.inputs[id].helpText
232230
});
233231

234232
this.inputs[id].valid = false;
@@ -244,7 +242,7 @@ function BugForm() {
244242
inlineHelp.appendTo('.wc-Form-information');
245243
}
246244

247-
if (id === 'image' || id === 'img_too_big') {
245+
if (id === 'image') {
248246
// hide the error in case we already saw one
249247
$('.wc-Form-helpMessage--imageUpload').remove();
250248

@@ -274,8 +272,7 @@ function BugForm() {
274272

275273
if (this.inputs['url'].valid &&
276274
this.inputs['problem_type'].valid &&
277-
this.inputs['image'].valid &&
278-
this.inputs['img_too_big'].valid) {
275+
this.inputs['image'].valid) {
279276
this.enableSubmits();
280277
}
281278
};
@@ -330,7 +327,7 @@ function BugForm() {
330327
var removeBanner = $('.wc-UploadForm-button');
331328
var uploadWrapper = $('.wc-UploadForm-wrapper');
332329

333-
// hide img_too_big errors (this will no-op if the user never saw one)
330+
// hide upload image errors (this will no-op if the user never saw one)
334331
$('.wc-Form-helpMessage--imageUpload').remove();
335332
$('.wc-UploadForm-label').show();
336333

0 commit comments

Comments
 (0)