Tuesday, May 10, 2016

jquery bind paste to get paste content





Below is the code for  jquery bind  paste to get paste content
        $('.coursepre').bind('paste', function(e) {
                //remove placeholder to make sure placeholder not mess with paste text
                $(this).attr("placeholder", "");

              //using setTimeout to get paste text
                 setTimeout(function ()
                {

                   //use $(e.currentTarget) to replace $(this) in paste
                    curname= $(e.currentTarget).val();
                    parent = $(e.currentTarget).parent();   
                     preid =  $(e.currentTarget).attr('data-preid');
                    saveBasicPre(curname, parent, stakeholder_id,pad_id,preid);           
               },0);                   
        });


We can use also add paste in jQuery  on  function
                $('#popup_9sp').on("keydown.autocomplete, paste",".course",function(e){
                $(this).autocomplete({              
                        //    autoFocus: true,
                    source: "../_ajaxParts/preplanning/preplanning.php?funct=courselist",
                    minLength : 2,

                    select : function(event, ui) {

                        $(this).val(ui.item.label);
                        newname = ui.item.value;
                        newvalue = ui.item.label;
                        checked = false;
                        parent = $(this).parent();
                        type='select';
                        campus = parent.find('.campus').val();
                        id =  $(this).parent().parent().attr('data-id');  
                      

              
                          managerttr=1;
                              
                          
                        saveBasicInfo1(row0,type,newvalue, parent, campus, id,sid,term, newname, managerttr,pad_id);

                    },
                    open : function() {
                       // $("#instructorname").attr('data-sid', 0);
                    },

                    change : function() {   
                            curname = $(this).val();
                            parent = $(this).parent();
                            type='change'
                            campus = parent.find('.campus').val();
                            id =  $(this).parent().parent().attr('data-id');
                                                  
                             newname=$('#tab1').find('.cid'+id).html();
                              managerttr=1;
              
                            if(curname.trim()!= newname) {
                                saveBasicInfo1(row0,type,curname, parent, campus, id,sid,term,newname,managerttr,pad_id);
                                //$(this).val(newname);
                             }
                    }
                    }).focus(function(){
                    //    $(this).autocomplete('search');
                        oldname=$(this).val();
                    });
                });              
              
                $('#popup_9sp .modal-body select.ttr, input.comment').die('change');
                $('#popup_9sp .modal-body select.ttr, input.comment').live('change', function(){  
                     row0.find('.ttrpattern').html($(this).val());
                     row0.find('.ttrpattern').attr('data-ttr',$(this).val());
                     row0.parent().find('.term').attr('data-ttr',$(this).val());
                     $td=row0;
                    if($(this).val()=='SL' || $(this).val()=='L'){
                        $td.find('.SLdate').html('');
                        $td.removeClass('teachingCell');  
                        $td.removeClass('researchCell');          
                        $td.addClass('leaveCell');
                        $(this).parent().find('.SLdate').hide();   
                        $td.find('.cidlist').hide();                          
                    }else if($(this).val()=='Research'){
                        $td.removeClass('leaveCell');  
                        $td.removeClass('teachingCell');
                        $td.addClass('researchCell');  
                         $(this).parent().find('.SLdate').hide();                      
                        $td.find('.cidlist').hide();  
                    }else if($(this).val()=='Teaching'){
                        $td.removeClass('leaveCell');  
                        $td.removeClass('researchCell');              
                        $td.addClass('teachingCell');
                         $(this).parent().find('.SLdate').show();   
                        $td.find('.cidlist').show();                        
                      
                    }else{
                        $td.removeClass('teachingCell');  
                        $td.removeClass('researchCell');          
                        $td.removeClass('leaveCell');  
                        $td.find('.cidlist').hide();  
                         $(this).parent().find('.SLdate').hide();   
                    }
                     ttrnew =     $(this).val();              
                    $.post("../_ajaxParts/preplanning/preplanning_summary.php", {
                            funct: 'savettrRevisedTerm',
                            ttrRevised:ttrnew,
                            stakeholder_id:sid,
                            pad_id:pad_id,
                            term: term
                    }, function(data) {
                        if(data=='fail')
                            $("div#notice").html('Updated failed!');
                        else        
                            $("div#notice").html('Updated successfully.');
                        $("div#notice").fadeIn();      
                        $("div#notice").fadeOut(5000);  
                     

                    });                  
                });  
                            

No comments:

Post a Comment