You need to sign in to do that
Don't have an account?

component.set('v.errors', null) doesn't work
var field1= component.find('field1');
var field2= component.find('field2');
var isValid = true;
if(!field1 || field1.get('v.value').length === 0) {
field1.set("v.errors", [{message:"Error message"}]);
isValid = false;
} else {
field1.set("v.errors", null); // here seems to be a problem..doesn't go to the nex line of code
}
if(!field2 || field2.get('v.value').length === 0) {
field2.set("v.errors", [{message:"Error message"}]);
isValid = false;
} else {
field2.set("v.errors", null);
}
Even both, the red border and error message, are removed doesn't go to the next line.
Someone has any idea?
var field2= component.find('field2');
var isValid = true;
if(!field1 || field1.get('v.value').length === 0) {
field1.set("v.errors", [{message:"Error message"}]);
isValid = false;
} else {
field1.set("v.errors", null); // here seems to be a problem..doesn't go to the nex line of code
}
if(!field2 || field2.get('v.value').length === 0) {
field2.set("v.errors", [{message:"Error message"}]);
isValid = false;
} else {
field2.set("v.errors", null);
}
Even both, the red border and error message, are removed doesn't go to the next line.
Someone has any idea?
I not aware of how your component is exactly working but based on your code I created a component to simulate the same behavior. I've found an error with your validation but this really depends of how the whole component works and API version, perhaps, you're not getting this error.
I'm sharing my example and I kindly ask you to give a try for the changes I've done in your JS code. Please let me know if it works. Feel free to share the whole component code too so we can try to reproduce the error.
Cmp (API 39):
JS Controller:
Hope to have helped!
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
All Answers
When you say next line, you mean that when the statement field1.set("v.errors", null); is executed the code stops there? Are you getting any javascript error in the browser console?
Client-side input validation is available for the following components:
lightning:input
lightning:select
lightning:textarea
ui:input*
Your fields must be of one of these types.
Hope to have helped!
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
I not aware of how your component is exactly working but based on your code I created a component to simulate the same behavior. I've found an error with your validation but this really depends of how the whole component works and API version, perhaps, you're not getting this error.
I'm sharing my example and I kindly ask you to give a try for the changes I've done in your JS code. Please let me know if it works. Feel free to share the whole component code too so we can try to reproduce the error.
Cmp (API 39):
JS Controller:
Hope to have helped!
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.