0

わかりましたので、データベース レコードを編集するためのフォームがあるダイアログ ボックスがありますが、データベースにレコードを追加するために同じフォームが使用されます。削除ボタンを追加したいのですが、attendance_id 入力がフィールドに ID が設定されました

ダイアログボックスが開くと、このフィールドにIDが設定され、IDが設定されている場合にのみこのボタンが表示されるようにする方法を見つける必要があります

        $( "#dialog-AL" ).dialog({
        autoOpen: false, 
        height: 530, 
        width: 650, 
        modal: true, 
        buttons: { 

            "Delete": function() {
            var attendance_id = $('#attendance_id').val();
                //more code here
            },

            "Submit": function() { 
            $('#anual_leave_form').submit(); },
            Cancel: function() {                        
                    $('#c1').val("");                       
                    $('#c1').html("");                      
                    $('#from').val("");                     
                    $('#to').val("");                       
                    tinyMCE.get('leave').setContent("");    
                    $('#attendance_id').val("");
                    $('#note_id').val("");                      
            $( this ).dialog( "close" );}}});   

これがオープンコードです

        $( ".edit" ).click(function() {
        var sub_id = $(this).attr("id");
        var sub_name = $(this).attr("name");
        var dataString = 'attendance_id=' + sub_id + '&note_id=' + sub_name + '&LabourHire=' + LabourHire;
            $.ajax({
                type: "POST",
                url: "<?php echo $process . 'process_editleave.php'; ?>",
                data: dataString,
                dataType: "html",
                cache: false,
                success: function(data) {
                    var result = $(data).filter('#d50').text();
                    $('#c1').val(result);
                    var result1 = $(data).filter('#d51').text();
                    $('#c1').html(result1);
                    var result2 = $(data).filter('#d52').text();
                    $('#from').val(result2);
                    var result3 = $(data).filter('#d53').text();
                    $('#to').val(result3);
                    var result4 = $(data).filter('#d54').text();
                    tinyMCE.get('leave').setContent(result4);
                    $('#attendance_id').val(sub_id);
                    $('#note_id').val(sub_name);
                    $( "#dialog-AL" ).dialog( "open" );                 
                },
                error: function() {
                alert('Error occured');
                }
            });
    });       
4

2 に答える 2

2

http://api.jqueryui.com/dialog/#option-buttonsを使用して、ボタンを動的に変更できます。$(selector).dialog('option','buttons', object)

ダイアログを作成する前に、ボタン用に 2 つのオブジェクトを作成します。

var dialogButtons = {
    "Submit": function() { /*code*/
    },
    Cancel: function() {  /* code*/
    }
}    
var dialogDeleteButton = {
    "Delete": function() { /* code*/
    }
}

次に、開く直前にボタンを変更します。

var buttons;
if ($('#attendance_id').val() != '') {
    buttons = dialogButtons;
} else {
    buttons = $.extend({}, dialogDeleteButton, dialogButtons)
}


$( "#dialog-AL" ).dialog('option','buttons', buttons).dialog('open') 
于 2012-10-30T21:40:42.280 に答える
0

AJAX 成功コールバックで必要に応じて表示する前に、ダイアログを作成するだけです。

    if(condition)
        $( "#dialog-AL" ).dialog({
        autoOpen: true, 
        height: 530, 
        width: 650, 
        modal: true, 
        buttons: { 

            "Delete": function() {
            var attendance_id = $('#attendance_id').val();
                //more code here
            },

            "Submit": function() { 
            $('#anual_leave_form').submit(); },
            Cancel: function() {                        
                    $('#c1').val("");                       
                    $('#c1').html("");                      
                    $('#from').val("");                     
                    $('#to').val("");                       
                    tinyMCE.get('leave').setContent("");    
                    $('#attendance_id').val("");
                    $('#note_id').val("");                      
            $( this ).dialog( "close" );}}});
    else
        $( "#dialog-AL" ).dialog({
        autoOpen: true, 
        height: 530, 
        width: 650, 
        modal: true, 
        buttons: { 
            "Submit": function() { 
            $('#anual_leave_form').submit(); },
            Cancel: function() {                        
                    $('#c1').val("");                       
                    $('#c1').html("");                      
                    $('#from').val("");                     
                    $('#to').val("");                       
                    tinyMCE.get('leave').setContent("");    
                    $('#attendance_id').val("");
                    $('#note_id').val("");                      
            $( this ).dialog( "close" );}}});
于 2012-10-30T21:26:23.103 に答える