• The AshokA
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi, I need to capture and show in the page any error that could happens. I have this component:
 
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" access="global">
    
    <!-- Define Attribute-->
    <aura:attribute name="newQuote" type="Object"/>
    <aura:attribute name="simpleNewQuote" type="Object"/>
    <aura:attribute name="newQuoteError" type="String"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <force:recordData aura:id="QuoteRecordCreator" 
                      layoutType="FULL"
                      targetRecord="{!v.newQuote}"
                      targetFields="{!v.simpleNewQuote}"
                      targetError="{!v.newQuoteError}" />

</aura:component>

and the controller:
 
handleSaveQuote: function(component, event, helper) {
            component.set("v.simpleNewQuote.SBQQ__Opportunity2__c", component.get("v.recordId"));
            component.set("v.simpleNewQuote.SBQQ__LineItemsGrouped__c", true);
            component.set("v.simpleNewQuote.SBQQ__Primary__c", true);
            component.find("QuoteRecordCreator").saveRecord(function(saveResult) {
                if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                    // record is saved successfully
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "type": 'success',    
                        "title": "Saved",
                        "message": "The new quote has been created."
                    });
                    resultsToast.fire();
                    helper.navigateTo(component, saveResult.recordId);


                } else if (saveResult.state === "INCOMPLETE") {
                    // handle the incomplete state
                    console.log("User is offline, device doesn't support drafts.");
                } else if (saveResult.state === "ERROR") {
                    // handle the error state
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "type": 'error',    
                        "title": "Not Saved",
                        "message": "The new quote has an error."
                    });
                    resultsToast.fire();
                    helper.navigateTo(component, saveResult.recordId);
                    console.log('Problem saving contact, error: ' + JSON.stringify(saveResult.error));
                } else {
                    console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
                }
            });
    }
if saveResult.state === "ERROR"  I need to show a message (like in the SUCCESS case) but it can be generic message, I must capture the error.

Could anyone help me please?
 
I would like to auto-populate slashes(/) in the date field, am unable achieve with below code.
Example:
Option 1: when user move cursor into date field Slashes(/) should be constant like __/__/____(MM/DD/YYYY)
Option 2: validate user date format: User should enter Date with Slashes and specified format(MM/DD/YYY) else field should throw an error with invalid date format.
Lighting Component
<ui:inputDate aura:id="Birthdate" label="Date Of Birth" 
                                                  value="{!v.value}" 
                                                  displayDatePicker="false" blur="{!c.formatDoB}"
                                                  format="MM/dd/yyyy" />
JS Controller
formatDOB: function(component, helper, event) {
        var DOB = component.find("Birthdate");
        var Date = DoB.get('v.value');
        var s = (""+Date).replace(/\D/g, '');
        var m = s.match(/^(\d{2})(\d{2})(\d{4})$/);
        var formattedDoB = (!m) ? null : + m[1] + "/" + m[2] + "/" + m[3];
        DoB.set('v.value',formattedDoB);
    },

any one please help?
Thanks