JavaScript focus() method will not work with ui:inputText field, however you can show red border, when value is missing, by following way :
if ((appName == null) || (appName == '')) { applicationName.set("v.errors", [{ message: "Please enter a Product/Application Name" }]); $A.util.addClass(applicationName, 'slds-has-error'); } else { $A.util.removeClass(applicationName, 'slds-has-error'); applicationName.set("v.errors", null); }
OR you can use lightning:input tags, this will support focus() method
<lightning:input label="Name" name="myname" value="{!v.testVal}" messageWhenValueMissing="Please enter a Product/Application Name" aura:id="Product/ApplicationName"/>
in javaScript : component.find('Product/ApplicationName').showHelpMessageIfInvalid(); component.find('Product/ApplicationName').focus();
Kindly let us know if it helps you, & close this query by selecting best answer if you got your solution, so this will helps other in future
JavaScript focus() method will not work with ui:inputText field, however you can show red border, when value is missing, by following way :
if ((appName == null) || (appName == '')) { applicationName.set("v.errors", [{ message: "Please enter a Product/Application Name" }]); $A.util.addClass(applicationName, 'slds-has-error'); } else { $A.util.removeClass(applicationName, 'slds-has-error'); applicationName.set("v.errors", null); }
OR you can use lightning:input tags, this will support focus() method
<lightning:input label="Name" name="myname" value="{!v.testVal}" messageWhenValueMissing="Please enter a Product/Application Name" aura:id="Product/ApplicationName"/>
in javaScript : component.find('Product/ApplicationName').showHelpMessageIfInvalid(); component.find('Product/ApplicationName').focus();
Kindly let us know if it helps you, & close this query by selecting best answer if you got your solution, so this will helps other in future
however you can show red border, when value is missing, by following way :
if ((appName == null) || (appName == '')) {
applicationName.set("v.errors", [{
message: "Please enter a Product/Application Name"
}]);
$A.util.addClass(applicationName, 'slds-has-error');
}
else {
$A.util.removeClass(applicationName, 'slds-has-error');
applicationName.set("v.errors", null);
}
OR you can use lightning:input tags, this will support focus() method in javaScript :
component.find('Product/ApplicationName').showHelpMessageIfInvalid();
component.find('Product/ApplicationName').focus();
Kindly let us know if it helps you, & close this query by selecting best answer if you got your solution,
so this will helps other in future
sfdcMonkey.com
All Answers
<lightning:input> or any aura UI component ?
can you share your code
Thanks
my component Code:
<ui:inputText aura:id="Product/ApplicationName"
value="{!v.objInfo.Product_Application_Name__c}"
onError="{!c.handleError}"
onClearErrors="{!c.handleClearError}"
maxlength="50"/>
helper method for valdiation:
onProdNameValidation: function(component, event, helper) {
var applicationName = component.find("Product/ApplicationName");
var appName = component.get("v.objInfo.Product_Application_Name__c");
if ((appName == null) || (appName == '')) {
applicationName.set("v.errors", [{
message: "Please enter a Product/Application Name"
}]);
var string = 'Error';
var err = component.get("v.ErrorString");
component.set("v.ErrorString", string);
component.set("v.prodnameboolean", false);
}
else {
applicationName.set("v.errors", null);
var err = applicationName.get("v.errors");
if (err == null) {
component.set("v.prodnameboolean", true);
}
}
},
I have tried focus() method its not wrking ?
however you can show red border, when value is missing, by following way :
if ((appName == null) || (appName == '')) {
applicationName.set("v.errors", [{
message: "Please enter a Product/Application Name"
}]);
$A.util.addClass(applicationName, 'slds-has-error');
}
else {
$A.util.removeClass(applicationName, 'slds-has-error');
applicationName.set("v.errors", null);
}
OR you can use lightning:input tags, this will support focus() method in javaScript :
component.find('Product/ApplicationName').showHelpMessageIfInvalid();
component.find('Product/ApplicationName').focus();
Kindly let us know if it helps you, & close this query by selecting best answer if you got your solution,
so this will helps other in future
sfdcMonkey.com