1

I am working on a lightning page where I have to use lightning input type= text. And this value I have to pass JS controller for the validation check. But when I am writing code below it is working fine:

<ui:inputText aura:id="fstname" label="First Name"
                              class="slds-input"
                              labelClass="slds-form-element__label"
                              value="{!v.newaccount.Name}"
                              required="true"/>`

({
    clickCreateAccount : function(component, event, helper) { 
        var validExpense = true; 
        var accnme = component.find("fstname");
        var aname = accnme.get("v.value");

        if (($A.util.isEmpty(aname))){
            validExpense = false;
            accnme.set("v.errors", [{message:"Name can't be blank."}]);
        }
        else {
            accnme.set("v.errors", null);
        }  
    }
})

For the same JS controller once I am writing the code on its throwing error:

<lightning:input aura:id="fstname" type="text" label="Account Name" class="slds-input"
                                     value="{!v.newaccount.Name}" required="true"/>

error:

This page has an error. You might just need to refresh it. Access Check Failed! AttributeSet.set(): 'errors' of component 'markup://lightning:input {18:0} {fstname}' is not visible to 'markup://c:NewAccount_contact {3:0}'. Failing descriptor: {c:NewAccount_contact}

I want to use "lightning:input" as my input text field and set the value to the field. Please help me in this!

4
  • It is wise to enable "debug" mode for issues like this. Will give you better error explanation. - developer.salesforce.com/docs/atlas.en-us.lightning.meta/… What is the access level of attribute "newaccount"? Commented Apr 22, 2018 at 18:52
  • <aura:attribute name="newaccount" type= "Account" default="{'sobjectType': 'Account', 'Name': '', 'Phone': ''}"/>
    – SFDC 44
    Commented Apr 22, 2018 at 18:53
  • And what is the access level at component level? Commented Apr 22, 2018 at 18:58
  • <aura:component > <aura:attribute name="Account" type="Account[]"/> <aura:attribute name="newaccount" type= "Account" default="{'sobjectType': 'Account', 'Name': '', 'Phone': ''}"/>
    – SFDC 44
    Commented Apr 22, 2018 at 19:08

2 Answers 2

1

Your issue is on these lines, where you are setting v.errors:

if (($A.util.isEmpty(aname))){
    validExpense = false;
    accnme.set("v.errors", [{message:"Name can't be blank."}]);
} else {
    accnme.set("v.errors", null);
}  

This will work fine as long as you use ui:inputText as this component supports errors attribute, which you can set from client side controller. Refer more on attributes supported by this component on its documentation here.

When you change your code to lightning:input, this component does not support errors attribute. And that is what the error message is complaining about:

'errors' of component 'markup://lightning:input {18:0} {fstname}' is not visible

You will need to handle the error messaging on the component using what is available or by writing some additional validations in your JS controller. Below is a snippet from the documentation for lightning:input, you can refer more on its documentation here.

Input Validation

Client-side input validation is available for this component. For example, an error message is displayed when a URL or email address is expected for an input type of url or email.

0

A component not having access system attribute may return undefined or cause access violation issues. In your case, adding access attribute like this - <aura:component access="public"> should solve the issue. Let me know if this works out.

Edit: As mentioned by jayant, accessing an unavailable attribute also causes access check failure. Sorry, I forgot to write about this.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .