0

JS don`t show alert message after second open window

asked 2018-05-02 19:38:39 +0800

Radoslav86 gravatar image Radoslav86
13 3

I have zul where I open new window with new VM. In new Window i hawe js code where i catch error for to big file

<window 
apply="org.zkoss.bind.BindComposer" closable="true"

onClose="@command('close')"
viewModel="@id('vm') @init('viewmodels.VM')">

<custom-attributes RL="${arg.resultListener}" />
<style>
    textarea[name=versioDdescription] 
        { 
            resize: none; 
        }
</style>
<hbox>
    <label>Version</label>
    <textbox value="@bind(vm.view.version)"
        maxlength="5" />
</hbox>
<space />
<vbox width="100%">
    <hbox>
        <fileupload label="Upload"
            onUpload="@command('upload')"/>
        <script type="text/javascript">
            var oldAlert = jq.alert; 
            jq.alert = function (msg, opts)
            {
            oldAlert(msg, opts); 
             if (!msg.indexOf('the request was rejected because its size' || 'Failed to mount: Invalid or unexpected token')) 
             oldAlert('The file is larger than 2MB. ', opts); 
            }
        </script>
        <label
            value="@load(vm.fileName eq null ? 'No File' : vm.fileName)" />
    </hbox>
    <space />
    <label>Description</label>
        <script type="text/javascript">

            </script>
    <hbox pack="center" width="100%">
        <textbox name = "versioDdescription" rows="8" cols="70"
            value="@bind(vm.view.description)" maxlength="250"/>
    </hbox>
    <button label="Save"
        onClick="@command('save',resultListener=RL)" />
</vbox>

</window>

When i open this window for first time and upload file larger than 2MB message is show, but if i close window and immediately open again if i upload file larger than 2MB message is not show.File is not upload but in stack trace i have exception "org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (40738509) exceeds the configured maximum (2097152)".

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-05-08 19:36:08 +0800

cor3000 gravatar image cor3000
6280 2 7

I can't fully follow what you are trying to achieve there since the JS code you wrote doesn't produce a useful result. See the line below. I think you should call indexOf again after the ||:

if (!msg.indexOf('the request was rejected because its size' || 'Failed to mount: Invalid or unexpected token'))

Also when opening the same window multiple times you are overriding the same function again while keeping the oldAlert at the global scope resulting in infite recursion / and stack overflow JS errors.

So here a working version of what I inferred you might intend to do (correct me if I'm wrong): http://zkfiddle.org/sample/13vm1c7/1-override-alert-function


BTW: Did you try overriding the max size error message using the default way? (available since ZK 8.0.0)

https://github.com/zkoss/zk/blob/master/zul/src/archive/metainfo/mesg/msgzul.properties#L77

my adding this to your zk-label.properties

MZul.2105=The file is larger than 2MB.
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2018-05-02 19:38:39 +0800

Seen: 9 times

Last updated: May 08 '18

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More