I recently suggested (in this post) a script that checks if the different fields of a form have an answer before allowing to submit and I did it using a client handler with
Couldn't see where to add a comment but I wanted to ask about the .addClickHandler(clihandler2); to the grid. This is accomplished by adding it at the end of the
grid.setText(0, 0, 'This is a ') [rest of the code (.setText .setWidget etc) ].addClickHandler(cliHandler2);
Also, can you let me know what the uploadtracker is on the widget position 9,0?? I didn't see it noted original code posted, but see upload and uploadtracker noted in the grid.set(text & widgets) in the revised piece of code.
The code adds a hidden elements which holds whether or not the FileUpload has been changed. If the FileUpload has been changed, it sets the TextBox to SELECTED!
but the user could just as easily change the FileUpload back to having no file selected, and there'd be no way to clear this TextBox accurately.
This is based on the few things that we know about a FileUpload.
So based on these 2 things, when change is called for the first time, we know that there is a file selected.
Create the hidden element
var hidden = app.createTextBox().setStyleAttribute("display","none").setValue("");
Remove .validateNotMatches(upLoad, 'FileUpload')
and replace it with
.validateLength(hidden,1,100)
Create a new ClientHandler
var cliHandler3 = app.createClientHandler().forTargets(hidden).setText("SELECTED!");
Insert .addChangeHandler(cliHandler3)
into the old line.
upLoad.addChangeHandler(cliHandler3).addChangeHandler(cliHandler2)
Replace panel.add(grid)
with (the "hidden" must be added to the FormPanel for it to work)
var vert = app.createVerticalPanel().add(hidden).add(grid);
panel.add(vert);