how to make read only field when i checked check box in page

  • 1
  • Question
  • Updated 6 months ago
  • Answered
once click to the inactive checkbox is true after I want to make read-only field otherwise field mode is read inline edit mode.

I have used some javascript for this functionality but read-only is work but when I uncheck inactive field than not able to edit.

var field = arguments[0], 
value = arguments[1]; 
//field.mode = 'read'; 
var $ = skuid.$;

var modelWF = skuid.model.getModel('Account');
    var modelWFSize = skuid.model.getModel('Account').data.length;
    var rowE = modelWF.getFirstRow();
    var checkInactive= rowE.Inactive__c;
    
    
    if(modelWFSize >0 && checkInactive == true){
        field.mode = 'readonly'; 
        console.log('====CHECKTRUE '+checkInactive);
        var renderers = skuid.ui.fieldRenderers; 
        var dt = field.metadata.displaytype; 
        var r = renderers[dt]; 
        if (!r) r = renderers.TEXT; 
        r.readonly(field,value);
    }
    if(modelWFSize >0 && checkInactive == false){
        console.log('====CHECKFALSE: '+checkInactive);
        field.mode = 'read';
        var renderers = skuid.ui.fieldRenderers; 
        var dt = field.metadata.displaytype; 
        var r = renderers[dt]; 
        if (!r) r = renderers.TEXT; 
        r.read(field,value);

        //console.log($('.nx-basicfieldeditor:visible').length);
        //var fieldeditor = $('.nx-basicfieldeditor:visible').data('object');
        //fieldeditor.mode = 'read' 
    }
    
Photo of Rajesh Kumar

Rajesh Kumar

  • 738 Points 500 badge 2x thumb

Posted 6 months ago

  • 1
Photo of Chandra V

Chandra V, Champion

  • 6,966 Points 5k badge 2x thumb
I do this by putting the field on the page twice, once in inline edit mode, the 2nd time in read only mode.  I then conditionally render the correct field based on your checkbox.
Photo of Rajesh Kumar

Rajesh Kumar

  • 738 Points 500 badge 2x thumb
thanks, @chandra for help.
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,040 Points 10k badge 2x thumb
In many cases, you can also set up Enable conditions on the field that needs to be in read-only mode. The enable conditions would work like render conditions, except that you don't need multiple copies of the field.

Edit: to add more detail to my explanation, I mean that you could set up an enable condition on the field, such that it is only enabled if the checkbox is checked. 
(Edited)