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

RJKRJK Member
edited February 4 in Questions
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' 
    }
    


Comments

  • Chandra VChandra V Member
    edited February 2019
    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.
  • RJKRJK Member
    edited October 2018
    thanks, @chandra for help.
  • Mark DeSimoneMark DeSimone Skuid Mod 🛠️ 
    edited February 4
    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. 
Sign In or Register to comment.