Skip to main content
Hi Guys!, How do I set the border of ui:InputTextArea in Red when the TextArea is invalid. I'm setting the Error message on error But the TextArea is not focusing in Red Color as it does with standard field. 

 

Any Idea how can I make the focus in Red?

<ui:inputTextArea aura:id="description" class="slds-input" value="{!v.data.Description}" rows="10" cols="250"

updateOn="keyup" keyup="{!c.handleChange}" errors="{!v.errors}"

maxlength="255" required="True" />

//In Controller.JS:

var newDesc = component.find("description").get("v.value");

if( newDesc == '' || newDesc == null){

component.find("description").set("v.errors", [{

message: "This field is required."

}]);}

 

 
2 件の回答
  1. 2018年11月19日 18:52

    Try this 

    //In Controller.JS:

    var newDesc = component.find("description").get("v.value");

    if( newDesc == '' || newDesc == null){

    component.find("description").set("v.errors", [{message: "This field is required."}]);

    $A.util.addClass(description, 'slds-has-error');

    }

    else {

    $A.util.removeClass(description, 'slds-has-error');

    component.find("description").set("v.errors", null);

    }

    also u can use a input tag and that support focus . this is pretty straight forward

    //put this tag somewhere in UI

    <lightning:input label="Name" name="test" value="{!v.testvalue}" messageWhenValueMissing="Please enter required value" aura:id="testinputtag"/>

    //Then inside ur JS call below based on ur scenario

    component.find('testinputtag').focus();

    U can refer this more more code related to custom required field features in lightning 

    https://salesforce.stackexchange.com/questions/145082/add-background-border-color-for-required-field-in-lightning-component

     

     
0/9000