1

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.

Thanks.

0

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" />

Controller:-

doinit : function (component, event, helper) {
   //call the server side action to get the profile name of user
   if(profilename !== correct){
     component.get("v.disableinput",true);
   }
}
  • 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 ? – SFKumar Aug 8 at 12:16
  • use a helper method to call another apex method. This way you can do it. – sanket kumar Aug 8 at 20:20
  • thanks, looks like good idea. I will try that. – SFKumar Aug 9 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.