5

On the Case object, I have a lightning component that displays only the fields of interest depending on the Status of the case. I have a separate Change_Status_To__c dependent picklist that actually controls what options are available to the user for updating the status (and automation in the backend actually changes the status).

I'm currently using lightning:recordForm to display the relevant fields, and would like to display just the Status field as read only. Is there anyway to single out/access this field and set it as read only?

All other fields should be editable, and would like to avoid using lightning:recordEditForm if possible

  • 1
    How are you passing fields to the recordform component is it through fields or reading fields from layout?. – RedDevil May 12 at 19:45
  • Through fields. I'm updating them dynamically based on the current Status, and I basically use an aura:if to turn off / on the component to load the fields properly. Otherwise there's weird behavior that the new fields just add on to the existing fields on the recordForm component – Brian Miller May 13 at 11:58
4

You won't be able to make a field read only specifically while using lightning:recordForm. It's either all fields or none which you could display as read only depending on the mode selected. The component operates based on the field level security, so if a field is not read only for a User, you cannot make one as read only on the component. Additionally there's not much support for client side validation on this component.

Your only option here as far as I can say is to utilize lightning:recordEditForm.

  • if for pulling fields layout is used and in the layout if we mark the field read only will that not work? – RedDevil May 13 at 7:53
  • I can't use the layout option because the fields are being adjust dynamically based on what status we're currently on – Brian Miller May 13 at 11:55
  • 1
    @JayantDas That's what I figured, and it's good to get a consensus that lightning:recordEditForm is the only way to go – Brian Miller May 13 at 11:57
  • 2
    @BrianMiller - if you are using filelds then jayant's answer is perfect – RedDevil May 13 at 11:59
1

Are you using the Fields / layoutType attributes for displaying the Fields . My suggestion would be to take out Status field from the above fields/Layout and display it using lightning:outputField. You're not submitting it as an editable form field anyways.

  • 1
    You can't use lightning:outputField in lightning:recordForm. Looks like I'll need to switch to lightning:recordEditForm – Brian Miller May 13 at 11:56
  • 1
    I meant using the lightning:outputField outside the lightning:recordForm. But then, you'll have to fetch its value. You can also use Both lightning:recordEditForm and lightning:recordForm in the same page to achieve it. That way your existing code works as it is. But yeah, if you can switch/convert to lightning:recordEditForm, then its the best bet. – Ajinkya Phadnis May 14 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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