unable to initialize the value of a ui-only checkbox field.

  • 1
  • Question
  • Updated 2 years ago
  • Answered
I have a UI field "boolIsPlanSelected" which is defaulted to "false" i.e. checkbox unchecked.
I am using this field just to toggle between the images of checked and unchecked checkbox. So when a user clicks an unchecked checkbox, the image should be flipped to a checked one and vice versa.

On the page load, the image of unchecked checkbox should be present, which requires me to check the value of this ui-only field in the rendering section of the image.

Now when i console.log the value of the ui-only field in the js snippet that runs on the click of the unchecked checkbox image, the value of the ui-only field is found to be "null".Why is the Default value not being considered?

var selectedItem = arguments[0].item,
    selectedList = arguments[0].list,
    selectedModel = arguments[0].model,
    selectedPlanRow = selectedItem.row;
    console.log('selectedPlanRow.boolIsPlanSelected = '+selectedPlanRow.boolIsPlanSelected);
    if(selectedPlanRow.boolIsPlanSelected){
        selectedPlanRow.boolIsPlanSelected = false;
    }
    else{
        selectedPlanRow.boolIsPlanSelected = true;
    }
    console.log('selectedPlanRow.boolIsPlanSelected 2 = '+selectedPlanRow.boolIsPlanSelected);
Photo of Rahul Sharma

Rahul Sharma

  • 212 Points 100 badge 2x thumb

Posted 2 years ago

  • 1
Photo of Christine Jessen

Christine Jessen

  • 670 Points 500 badge 2x thumb
Hi Rahul!

I just answered your other question - and hopefully you have this all working now.  The UI-Only field default values only applies to new records, and not existing records.  In your use case, I would check to see if the checkbox is either null or false, and render based on that value.  A null value would just represent an existing record where the UI-Only field hasn't ever been set to true.

Hope this fixes it!
Christine