0

I have this JavaScript code for my SharePoint forms which does not work in other browsers but works in Internet Explorer.

By using jQuery, when you initially open the task, the Rejected button will be shown as disabled and it will only enable when you add comments.

$(document).ready(function(){
    var reject = "input[name='Status_c15b34c3-ce7d-490a-b133-3f4de8801b76_$DropDownChoice_Rejected']";
    var tooltip = 'Please enter comments to reject the task';

    $(reject).attr('title',tooltip);

    $(reject).attr('disabled','disabled');

    $("textarea[Title='Append-Only Comments']").closest("span").find("iframe[Title='Rich Text Editor']").contents().find("body").keyup(function(){ 
        disableReject();
    });

    function disableReject(){
        var comments = $("textarea[Title='Append-Only Comments']").closest("span").find("iframe[Title='Rich Text Editor']").contents().find("body").find('div').text().trim().length;

        var reject = "input[name='Status_c15b34c3-ce7d-490a-b133-3f4de8801b76_$DropDownChoice_Rejected']";

        if(comments > 0){
            $(reject).removeAttr('disabled');
        }
        else{
            $(reject).attr('disabled','disabled');
        }
    }
});

Can you please check the code and let me know the changes to be made to work in chrome

1
  • 1
    Is there any console errors? Also, hard-coding the GUID into the selector like that, will be difficult to manage in the long run. Lastly, cache the $(reject) result rather than re-querying each time.
    – MackieeE
    Jun 4, 2014 at 15:31

1 Answer 1

0
    //Check the contents of the div within the Editor, with the
    //Cached $editor selection
    function disableReject(){
       $editor.find('div').text().trim().length;

       if( comments > 0 ){
           $reject.removeAttr('disabled');
       } else {
           $reject.attr('disabled','disabled');
       }
    } 

    $(document).ready(function(){

        var rejectSelector = 
               "input[name='Status_c15b34c3-ce7d-490a-b133-3f4de8801b76_$DropDownChoice_Rejected']";

        //Cache the Input selector
        var $reject = $(rejectSelector);

        //Cache the editor selector result
        var $editor = 
              $("textarea[Title='Append-Only Comments']")
                    .closest("span")
                    .find("iframe[Title='Rich Text Editor']")
                    .contents()
                    .find("body");

        //Setting an .attr returns an jQuery object
        $reject.attr('title', 'Please enter comments to reject the task' )
               .attr('disabled','disabled');

        $editor.keyup(function(){ 
            disableReject();
        });
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.