samach
samach

Reputation: 3394

browse file button in jquery UI dialog

i am using jquery dialog and in that dialog im trying to put a browse button. for browsing, i am using "uploadify" plugin. now the problem is how can i add the uploadify button to the ui dialog? to use the uploadify button we hav to declare <input type="file" id="myId"> in our html code. how can i link this file type button so that it works with the dialog? the confusion is that for ui dialog buttons we have to set the button property as

buttons:{
    "Done": function() {
        processData();
        $( this ).dialog( "close" );
    } 

so how can i create a file type input button on the dialog, and assign it an id? ( i hav to set the "id" cauze to make a file type button work with uploadify we do $("#myId").uploadify() )

Upvotes: 0

Views: 1714

Answers (1)

Alexander Kahoun
Alexander Kahoun

Reputation: 2488

As an alternative, you could execute the processData() function on the close event of the dialog if it validates and use .live() on the button id to close the dialog. So something like this:

Html:

<input type="file" id="myId">

Javascript:

$('#yourDialog').dialog({
    close: function(event, ui) {
        // validate something was picked
        processData();
    }
});
$('#myId').live('click', function() {
    if (event.preventDefault) {
        event.preventDefault();
    } else {
        event.returnValue = false;
    }
    $('#yourDialog').close();
});

Upvotes: 1

Related Questions