function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VINODKUMAR REDDY KALUVAVINODKUMAR REDDY KALUVA 

How can I achieve the below functionality in Salesforce Lightning

I have three field types they are 1.Checkbox  2. Textarea 3.Date.

1. Here The Textarea field default some text will be there whenever I check(True) the Checkbox in the form I want to insert a new sentence to Textarea field dynamically.
2. And here the one more Whenever I select a date from the date(using date picker) field I want to push selected date to textarea field in the form.

How can I achieve that in salesforce Lightning, someone please help me!...
Khan AnasKhan Anas (Salesforce Developers) 
Hi Vinod,

Please try the below code. Kindly modify the code as per your requirement.

Application:
<aura:application extends="force:slds">
    <c:KhanTest/>
</aura:application>

Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="RegForm" type="Khan__c" default="{'sobjectType' : 'Khan__c',
                                                           'Text_Area__c' : 'Default Text'}"/>
           
    <div class = "slds-size--3-of-8">
        <lightning:input label="Text Area" 
                         name="text" 
                         value="{!v.RegForm.Text_Area__c}"/>
        <br/>
        <lightning:input type="checkbox" 
                         aura:id="chk"
                         label="Check Box" 
                         name="checkbox" 
                         value="{!v.RegForm.Check_Box__c}"
                         onchange="{!c.onChange}"/>
        <br/>
        <lightning:input type="date" 
                         label="Custom Date" 
                         name="customdate" 
                         value="{!v.RegForm.Date_Custom__c}"
                         onchange="{!c.dateChange}"/>
        <br/>
    </div>
</aura:component>

Controller:
({
    onChange : function(component, event, helper) {
        var checked = component.find('chk').get("v.checked");;
        console.log('Checked? --> ' + checked);
        if(checked == true){
            component.set('v.RegForm.Text_Area__c', 'Enter your new text');
        }
        if(checked== false){
            component.set('v.RegForm.Text_Area__c', '');
        }
    },
    
    dateChange : function(component, event, helper) {
    	var dt = component.get("v.RegForm.Date_Custom__c");
        console.log('Date select -> ' + dt);
    	component.set('v.RegForm.Text_Area__c', dt);
	}
})

I hope it helps you.

Kindly let me inform if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas