Upload - Browse button disabling

Apologies for the long winded explanation, but here it goes:

I have an UploadPanel component. Requirement was to display on the form, but not allow any uploads if a combobox on the form had a specific value i.e. a combobox would determine whether or not the UploadPanel was enabled / disabled.

We ran into issues whereby we added a ValueChangeListener to the combobox, and when a specific value was selected, we would enable / disable the UploadPanel. This approach did not work ALL of the time i.e. sometimes the enabling / disabling would work, other times not. Not sure if actions that alter the state of a component within a listener cannot be guaranteed?

In any case, we have gone with a different approach. Not the cleanest solution, but the idea was that we would always enable the UploadPanel but block the upload if the combobox had a specific selection / value. This was done with via the StartedListener():

upload.addListener(new Upload.StartedListener() { @Override public void uploadStarted(Upload.StartedEvent event) { //Interrupt the upload if we should block it if (isBlocked()) { upload.interruptUpload(); } } }); Problem is the user would have already gone through the process of selecting a file i.e. the browse button, and then clicked on upload button (see attachment).

Now I know the browse button is handled by the Internet browser you are using i.e but is it at all possible to block the browse button within Vaadin?

Alternatively, does anyone have any good suggestions whereby we could ultimately disable the upload process completely (including file navigation) based on the value within a combobox?

18933.png

Hmm, can’t think of any reason why enabling/disabling wouldn’t work from within a ValueChangeListener as long as the field is immediate and doesn’t need to stop to wait for some other action to trigger a server round trip, and that the listener is already there when the initial value is set if you need the triggering then already. BlurListener is another common place to toggle such things. It’s possible the blocking could be done later as well, probably from the client-side, but I would imagine that fixing whatever issue it is that is messing with your disabling would be simpler.