I am trying to set checkbox value as default. Below is the code.

 <label class="slds-form-element__label">Is Active</label>
    <force:inputField  value="{!v.Opp.Active__c}" />

Can someone let me know how to set.

  • As you are using force:inputField try to set the checkbox field default value set to checked instead of unchecked that must show you checked it on the new record. It's just a guess not sure it will work or not. – itzmukeshy7 Feb 6 at 12:42

The place to populate default data values is either in your declaration of your <aura:attribute>:

<aura:attribute name="contact" type="Contact" 
           default="{ 'sobjectType': 'Contact', 'LastName': 'Schmoe' }"/>

or in your controller, if, for example, you wish to populate data from the server into an attribute and then make changes, or dynamically create a new object:

     doInit : function(component, event, helper) {
        var action = component.get("c.getContact");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                let cont = response.getReturnValue();
                cont.LastName = "Schmoe";
                // Add a default value (not persisted to the database!)
                component.set("v.contact", cont);

if opp is the attribute name, then do this in your init function

var oppDefault = cmp.get("v.opp");


Note : Syntax might not be accurate, you get the idea that defaulting should be in attribute default parameter for strings etc, or in the init function for objects



I think you can set it in doInit method. Below is the sample code.

Code in Component

<force:inputField value="{!v.Opp.Active__c}">

Code in controller

doInit : function(cmp, event, helper){
    var opp = cmp.get("v.Opp");
    opp.Active__c = true;
    cmp.set('v.Opp', opp);
  • I have to make Active__c = true when opp.Type = 'New'. If opp.Type = 'Old' then Active__c=false. – SFDC Guest Feb 6 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.