You need to sign in to do that
Don't have an account?
Lauren B
In the below code i have put alert message to show duplicate emails. But my requirement is to put error message below the field instead of alert message.I have used lightning aura component.
Error message below the field.
In the below code i have put alert message to show duplicate emails. But my requirement is to put error message below the field instead of alert message.I have used lightning aura component.
Apex- @AuraEnabled global static String getEmails(String emailstring){ Integer len=emailstring.length(); List<contact> con; if(len>0 && emailstring!=''){ con=[select id,Email from contact where email=:emailstring]; } system.debug('Emails checll-------'+con); String msg='Email already exists'; string msg1=''; if (con.size()>0){ return msg; } else return msg1; } HTML- <lightning:input class="inputfields" aura:id="email" label="Email" type="Email" name="email" value="{!v.newContact.Email}" required="true" messageWhenValueMissing="Please enter your Email" pattern="^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$" messageWhenPatternMismatch="Please Enter a valid Email Address" onchange="{!c.handleOnChangeEmail}"/> JS- handleOnChangeEmail:function(component, event, helper) { console.log('Email---'); var action=component.get("c.getEmails"); action.setParams({ "emailstring":component.get("v.newContact.Email") }); action.setCallback(this, function(response) { var state= response.getState(); if(state==='SUCCESS'&& response.getReturnValue()!=''){ console.log('responseEmail---'); alert(response.getReturnValue()); component.set("v.newContact.Email",''); }}); $A.enqueueAction(action); },
Also, I am unsure if it it work but you can try leveraging <lightning:notificationsLibrary aura:id="notifLib"/> as well
Let me know if this helps
I have below link for documentation that has an implementation to show error under a field:
Link: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_validate_fields.htm
I hope this helps and in case if this comes in handy can you please choose this as the best answer so that it can be useful for others in the future.
Regards,
Anutej