You need to sign in to do that
Don't have an account?
Ertyq Mrsk
Text Field Not Formatted in Currency When Selecting Currency Symbol from Dropdown List
I've been repeatedly modifying a Salesforce LWC page which aims to format a text field into a currency format (with corresponding currency symbols, commas, and decimals). Displayed currency symbol depends on the selected value from Currency__c field.
Since I wanted to format the inputted text value when user leaves that input field, I used javascript's onblur event.
But upon leaving the input field, a Lightning error occurs, like the following:
Also, I checked the browser's console log, and it displays the value inputted from the text field. I am not sure what is wrong with my page. I even checked some tutorials if I got the correct event, and looks like onblur fits my requirement.
Meanwhile, below are the latest codes:
customDropDownLWC.js
Since I wanted to format the inputted text value when user leaves that input field, I used javascript's onblur event.
But upon leaving the input field, a Lightning error occurs, like the following:
Also, I checked the browser's console log, and it displays the value inputted from the text field. I am not sure what is wrong with my page. I even checked some tutorials if I got the correct event, and looks like onblur fits my requirement.
Meanwhile, below are the latest codes:
customDropDownLWC.js
//portion of js file @wire(getPicklistValuesByRecordType, { objectApiName: CUSTOM_OBJECT, recordTypeId: '$objectInfo.data.defaultRecordTypeId'}) currencyPicklistValues({error, data}) { if(data) { this.error = null; let currencyOptions = [{label:'--None--', value:'--None--'}]; data.picklistFieldValues.Currency__c.values.forEach(key => { currencyOptions.push({ label : key.label, value: key.value }) }); this.currencyValues = currencyOptions; } else if(error) { this.error = JSON.stringify(error); } } handleCurrencyDropDownChange(event) { this.custObj.Currency__c = event.target.value; this.selectedCurrency = this.custObj.Currency__c; } handleTextFieldChange(event) { this.custObj.Text_Field__c = event.target.value; const currencySelected = this.custObj.Currency__c; console.log('Currency Selected' + currencySelected); if(currencySelected === '$') { var formattedString; console.log('Text Field' + this.custObj.Text_Field__c); formattedString = '$' + this.custObj.Text_Field__c.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, "$&,"); console.log('Formatted Text Field' + formattedString); } //same goes with other currency symbols.... }customDropDownLWC.html
<!--portion of html template--> <lightning-combobox label="Currency" name="Currency" onchange={handleCurrencyDropDownChange} options={currencyValues} placeholder="--None--" value={custObj.Currency__c}> </lightning-combobox> <lightning-input label="Text Field" type="text" value={formattedString} onblur={handleTextFieldChange}> </lightning-input>
The code looks fine to me.
"-1934174971" With this Error ID raise a case with Salesforce support team so our team check-in our internal logs and get back to you.
I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.
Thanks.