Monday, June 27, 2016

How to disable Choose button in PrimeFaces fileupload component


The javascript function is to disable "Choose" button in <p:fileUpload /> component a file has been uploaded.
It is applicable to PrimeFaces 3.5

function below will find the Choose button from the passed in widgetVar when the file component onchange,
if the number of uploaded files more than 1,
disable the Choose button.


<script type="text/javascript">

    function onchangeDisableChooseBtn(upload_widget_var) {
        if(upload_widget_var.buttonBar.find('input[type=file]').get(0).type == 'file') {
            upload_widget_var.buttonBar.find('input[type=file]').change(function() {
                var files = upload_widget_var.uploadContent.find('.files tr');
                if (files.length >= 1) {
                    upload_widget_var.buttonBar.find('input[type=file]').get(0).disabled=true;
                }
                onchangeDisableChooseBtn(upload_widget);
            });
        }
    }

</script>



Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...