#20855 closed task (blessed) (fixed)
Don't show Upload button until file has been selected.
Reported by: | jane | Owned by: | kovshenin |
---|---|---|---|
Milestone: | 3.5 | Priority: | normal |
Severity: | minor | Version: | 3.4 |
Component: | Administration | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
There's an awkward UI situation in places (such as header image upload) where we show two secondary buttons at the same time, one to choose file and one to upload the file you will have theoretically already chosen before clicking upload.
It would be better ux to show the choose file button by default, and then only show the Upload button after a file has been selected.
Konstantin made this work in a project we're doing, have asked him to turn it into a patch for core.
Attachments (18)
Change History (62)
@
12 years ago
Patching the functionality and described in the ticket. Hides the 'Upload' button until a file has been provided. Created necessary dev files and updated minified files, as well. Register scripts using the script loader.
@
12 years ago
Neglected to properly include the new JavaScript files in the initial patch. Providing the full working copy in this patch.
@
12 years ago
Adding the fully working copy for improvements to both the user experience of the Custom Header page and the Custom Background page.
#3
follow-up:
↓ 4
@
12 years ago
The current patches (*.3.patch being the full working copy) that I've contributed provide a solution for hiding the 'Upload' button until the 'Choose Image' input element values have changed for both the Custom Header and Custom Background pages.
One concern that I have is that there is code duplication between custom-header.dev.js and custom-background.dev.js as well as their minified counterparts:
Namely (the unminified code), this exists in both files:
// Watch for the value of the "Choose Image" field to change... $('#upload').change(function() { // If the upload field is empty, we'll hide te upload button, // Otherwise, let's show it. if( '' === $('#upload').val() ) { $('#submit').hide(); } else { $('#submit').show(); } // end if/else });
Ideally, I'd like to collapse this into a single JavaScript file (perhaps custom-upload.dev.js?) so that the code isn't duplicated; however, I'm unfamiliar with what's considered a best practice in this case.
Secondly, I've manually updated the minified versions of the related stylesheets and JavaScript, too. Is this typical practice or do you look for *.dev.js and *.dev.css to be contributed in patches and then run minification on your end?
Looking to you @kovshenin and @jane for advice on this - thanks!
#4
in reply to:
↑ 3
;
follow-up:
↓ 5
@
12 years ago
- Keywords has-patch added; needs-patch removed
Replying to tommcfarlin:
Patches should only be for *.dev.* files, using the SCRIPT_DEBUG constant in your dev environment to test those changes. bumpbot will take care of the minification of files when needed, post-commit :)
#5
in reply to:
↑ 4
;
follow-up:
↓ 6
@
12 years ago
Replying to helenyhou:
Replying to tommcfarlin:
Patches should only be for *.dev.* files, using the SCRIPT_DEBUG constant in your dev environment to test those changes. bumpbot will take care of the minification of files when needed, post-commit :)
Helen - thanks! First time applying a patch to core so just trying to make sure I get it correct.
I'd like to back and make this patch proper. What's typically considered best etiquette - provide a new patch with a full working copy or a patch that essentially rolls back the above patches in addition to the new work?
#6
in reply to:
↑ 5
@
12 years ago
Replying to tommcfarlin:
What's typically considered best etiquette - provide a new patch with a full working copy or a patch that essentially rolls back the above patches in addition to the new work?
A new patch similar to your latest one, but excluding the minified files, is all that's needed.
#7
@
12 years ago
In 20855.diff
Using hide-if-js
class to hide the submit button only if js is working. Moved action and nonce fields above the file field so that the file field and submit field are immediate siblings, and thus jQuery.next()
can be used.
I don't really like the way hide-if-js is added to the button, since that argument is actually a "type" and not "class". Maybe we should wrap the submit button in a span with a hide-if-js class (and another class to target in js) instead. Thoughts?
#8
@
12 years ago
I tested 20855.diff, and it looks good. Though this select box UI may change with the media manager overhaul (just a heads up).
#10
@
12 years ago
Instead of using show / hide maybe we should use disabled so the button appears but is disabled until there is a file.
$( '#upload' ).change( function() { if( '' === $( '#upload' ).val() ){ $( '#upload-form #submit' ).attr( 'disabled', 'disabled' ); }else{ $( '#upload-form #submit' ).removeAttr( 'disabled' ); } })
#11
@
12 years ago
.prop() needs to be used (jQuery 1.6+), rather than .attr(). Something like this would work:
$('#upload-form #submit').prop('disabled', '' === $('#upload').val() );
#12
@
12 years ago
20855.3.diff disables the button instead of hiding.
#13
@
12 years ago
I would imagine this same disabling should be done in similar places, e.g. uploading a plugin or theme.
#14
@
12 years ago
20855.4.diff does the same when uploading a plugin or theme.
#15
@
12 years ago
Looks lovely. Left comments about things this patch made me notice about the buttons over on #21598.
#18
@
12 years ago
20855.7.diff is an attempt to use more generic JS.
#19
@
12 years ago
20855.8.diff is looking good to me. Tested header, background, add plugin, add theme, and import screens with and without JS.
#21
follow-up:
↓ 22
@
12 years ago
Tested in Mac FF & Chrome, Win FF & Chrome & IE7. Works in all except IE7, but I think we can let that slide...
+1 to 20855.8.diff.
#22
in reply to:
↑ 21
;
follow-up:
↓ 23
@
12 years ago
Replying to lessbloat:
Tested in Mac FF & Chrome, Win FF & Chrome & IE7. Works in all except IE7, but I think we can let that slide...
Tested in IE7 and IE8, seems to work in both.
#23
in reply to:
↑ 22
@
12 years ago
Replying to SergeyBiryukov:
Tested in IE7 and IE8, seems to work in both.
Maybe I should clarify. The upload functionality worked for me in IE7, but the "upload" button was not disabled.
#24
follow-up:
↓ 25
@
12 years ago
Also works in IE7 for me. Was JS perhaps off in your IE7? It won't be disabled if JS is off.
#25
in reply to:
↑ 24
@
12 years ago
Replying to helenyhou:
Also works in IE7 for me.
What do you know... Hard refresh and it works.
Sorry for the false alarm. :-)
#26
@
12 years ago
common.js changes seem like they need a bit of cleanup, but otherwise, this is good.
#28
@
12 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
20855.9.diff adds the same behaviour to the browser upload form on wp-admin/media-new.php
.
#29
@
12 years ago
Not sure if the form in the old media modal should also be patched. Will it be removed in RC?
Could not test the form in the new media modal yet: #22444
#30
@
12 years ago
With 20855.9.diff, the button doesn't seem to re-enable after a file is selected.
#31
@
12 years ago
- Cc mdhansen@… added
I am seeing the same problem on Ubuntu + FF16. The upload button does not become enabled after selecting a file.
#32
@
12 years ago
Turned out the screen also has the Plupload form (invisible if browser uploader is displayed):
<input type="file" multiple="multiple" accept="" style="font-size: 999px; position: absolute; width: 100%; height: 100%;" id="p17c0hrb00la712kf81o1t0svoi0_html5">
20855.10.diff adds filter(':visible')
. The reason for it to be inside the function is to make sure it works when the Plupload form is initially displayed.
#34
@
12 years ago
This is pretty much the main fear here, right? Something designed to make this a better experience ends up trapping the user into being unable to upload? There are hooks in media_upload_form() that could be used to render additional form controls, so I'm wondering if this needs more poka yoke than just :visible.
#35
follow-up:
↓ 36
@
12 years ago
20855.11.diff is an attempt to use button.prev('input[type="file"]')
to get the closest input element. Doesn't work for wp_import_upload_form()
though.
#36
in reply to:
↑ 35
;
follow-up:
↓ 38
@
12 years ago
SergeyBiryukov: sounds like you're looking for jQuery.closest()?
#37
@
12 years ago
20855.12.diff uses the closest element if it exists and falls back to form.find()
otherwise. Seems to work for all current use cases.
#38
in reply to:
↑ 36
;
follow-up:
↓ 39
@
12 years ago
Replying to kovshenin:
SergeyBiryukov: sounds like you're looking for jQuery.closest()?
No, jQuery.closest()
won't find a sibling element.
#39
in reply to:
↑ 38
;
follow-up:
↓ 40
@
12 years ago
Replying to SergeyBiryukov:
Oh, that's true, gotcha! 20855.12.diff looks reasonable and works in this case, but I think it's pretty fragile, since it will break if there's any other element between the file input and the submit button, because of the way .prev() works. The media upload form has two file inputs, and two submit buttons, which makes me think: what if they were all visible? :)
We can concatenate all the file input values with .map and check for an empty string. That will enable all submit buttons in a form if at least one file input has a value, which sounds like it could break less. Besides, we'd rather "not disable the submit button when we need to" than "not enable the submit button when we need to." Thoughts?
#40
in reply to:
↑ 39
@
12 years ago
Replying to kovshenin:
We can concatenate all the file input values with .map and check for an empty string. That will enable all submit buttons in a form if at least one file input has a value, which sounds like it could break less.
Sounds like a great idea to me.
#41
@
12 years ago
- Component changed from UI to Administration
20855.14.diff seems sane to me, and appears to work in all places.
#43
@
12 years ago
[22663] broke media-new.php. "Save All Changes" remains disabled despite the fact that the browser uploader is hidden.
To test this, you must be on r22750, prior to the changes in media-new.php, and upload one or more files using Plupload.
I'm going to revert a piece of [22663] to avoid breaking anything crazy being done by plugins on this page. Other forms are far simpler and should be okay.
Two buttons at same time