문제

I am looking for a jQuery script to conditionally disable two field types:

  1. Disable a text field if it is not blank and
  2. Disable a number field once it is non zero.

I see many posts on disabling People Pickers and Date fields, but not the above.

Thank you for you help.

도움이 되었습니까?

해결책

Assuming you want to disable the form fields on Edit form.

For Single line of text field: Consider column name is - Title

$(document).ready(function(){
    if($("input[title^='Title']").val()) {
        $("input[title^='Title']").attr("disabled", "disabled");
    
        //$("input[title^='Title']").attr("readonly", "readonly");
    }
});

For Number field: Consider column name is - Content Amount

$(document).ready(function(){
    if($("input[title^='Content Amount']").val() != "0") {
        $("input[title^='Content Amount']").attr("disabled", "disabled");
        
        //$("input[title^='Content Amount']").attr("readonly", "readonly");
    }
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top