I have an Action button in our lightning Page, upon clicking it shows a form to input couple of fields and save it. But I have to make those input fields readonly for Profile 1 and editable for Profile 2.

Let me know how I can achieve this. If possible within Lightning component itself by checking profile of the current user, As I am already calling server side script upon clicking this button.



You can do that by calling a apex method to check the profile name of current user on load of the form by using init handler in your component.

After that, You can use disable property of lightning:input field and assign the value to disable property according to the profile name.You can define an attribute in your component markup and evaluate it in your controller based on profile name.

Component markup:-

<aura:handler name="init" value="{!this}" action="{!c.doinit}" />
<aura:attribute name="disableinput" type="Boolean" default="false"/>
<lightning:input name="input5" disabled="{!v.disableinput}" value="initial value" label="Disabled text field with a predefined value" />


doinit : function (component, event, helper) {
   //call the server side action to get the profile name of user
   if(profilename !== correct){
  • But I am already calling another functionality related apex method in the doinit when the button is clicked, not sure if i can return multiple values from apex. Is it possible for me to return 2 return values from apex and use the same, one of them will be to check the profile and make readonly ? Aug 8 '19 at 12:16
  • use a helper method to call another apex method. This way you can do it. Aug 8 '19 at 20:20
  • thanks, looks like good idea. I will try that. Aug 9 '19 at 10:23

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.