1

When pasting text by mouse.Submit button should be enable . when remove full text from text area , submit button should be disable. If remove partial text by mouse. Submit button should be in enable state. How can I debug issue.

...
Jquerry

$(document).ready(function()
 {
 $("#feedbackText").bind(function()
    {        
        paste:function()
        {
            ToggleFeedbackSubmit();
        },
        cut:function()
        {
          ToggleFeedbackSubmit();
        }       

   });   
});    

.....

function ToggleFeedbackSubmit()
    {
        var feedbackText=document.getElementById("feedbackText");
        if(feedbackText!=null)
        {
            if(feedbackText.value.length > 0)
            {
                $('#feedbackSubmit').addClass("orange");
                $('#feedbackSubmit').prop('disabled', false);
            }
            else
            {
                $('#feedbackSubmit').removeClass("orange");
                $('#feedbackSubmit').prop('disabled', true);
            }
        }
    }
5
  • 2
    Here's a good staring place for debugging your Javascript: How do I start to debug my own Visualforce/JavaScript?
    – BarCotter
    Sep 19, 2014 at 10:54
  • 1
    So if you follow @BarCotter recommendation, tell us what happens or not happens exactly. Look into the console tab a tell us if you get any errors. Your basic approach looks OK. I would put ToggleFeedbackSubmit() above $(document).ready() - but it possibly won't make a big difference here
    – Uwe Heim
    Sep 19, 2014 at 11:39
  • note that the copy, cut, paste events may be different in browsers, especially expect older IEs to behave bad. Also FF<v22 may have limitations.
    – Uwe Heim
    Sep 19, 2014 at 11:42
  • I used like this , paste is now working .only issue with cut .
    – user10584
    Sep 19, 2014 at 12:26
  • $(document).ready(function() { $("#feedbackText").bind({ paste:function() { $('#feedbackSubmit').addClass("orange"); $('#feedbackSubmit').prop('disabled', false); }, cut:function() { ToggleFeedbackSubmit(); } }); });
    – user10584
    Sep 19, 2014 at 12:32

1 Answer 1

2

this is mostly a javascript / jquery issue and nothing to do with salesforce / visualforce.

when the cut / paste event is fired, the value of the text element you are checking will still hold the original text and not the updated text

see these discussions for better understanding

https://stackoverflow.com/questions/9364617/get-the-value-of-a-textbox-during-cut-event

https://stackoverflow.com/questions/2242442/capture-text-pasted-into-a-textarea-with-jquery

its better to directly bind it to the change event on the textbox and enable / disable the button based on the textbox value

$(document).ready(function(){
   $("#feedbackText").change(function(){        
       ToggleFeedbackSubmit();
   });   
});

        function ToggleFeedbackSubmit(){
            if($('#feedbackText').val() != '')
            {
                $('#feedbackSubmit').prop('disabled', false);
            }
            else
            {
                $('#feedbackSubmit').prop('disabled', true);
            }
        }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .