Form validation using client handler : why does input sequence order change the result?

前端 未结 2 850
情歌与酒
情歌与酒 2020-12-22 07:08

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

相关标签:
2条回答
  • 2020-12-22 07:38

    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.

    0 讨论(0)
  • 2020-12-22 07:40

    Crude workaround

    > It's not perfect

    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.

    1. When a user loads the UiApp, the FileUpload initially has no file selected.
    2. When the change event is fired on a FileUpload, the selected file has changed.

    So based on these 2 things, when change is called for the first time, we know that there is a file selected.

    > Summary of changes

    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);
    
    0 讨论(0)
提交回复
热议问题