• Wade Lovell 21
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 6
    Replies
Re-factored my code from previous units with base lightning components, but receiving this error.  Here's my new form component.  Any help would be much appreciated.

<aura:component >   
    <aura:attribute name="newItem" type="Camping_Item__c"    default="{ 'sobjectType': 'Camping_Item__c',
                         'Name': '',
                         'Price__c': 0,
                         'Quantity__c': 0,                         
                         'Packed__c': false
                       }"/>
 
    <aura:registerEvent name="addItem" type="c:addItemEvent"/>
    <lightning:layout >
        <lightning:layoutItem padding="around-small" size="6">
<div aria-labelledby="newItemForm">

    <!-- BOXED AREA -->
    <fieldset class="slds-box slds-theme--default slds-container--small">

    <legend id="newItemForm" class="slds-text-heading--small 
      slds-p-vertical--medium">
      Add Camping Item
    </legend>

    <!-- CREATE NEW CAMPING ITEM FORM -->
    <form class="slds-form--stacked">          
        <lightning:input aura:id="itemForm" label="Camping Item Name"
                         name="Name"
                         value="{!v.newItem.Name}"
                         required="true"/> 
        <lightning:input type="number" aura:id="itemForm" label="Quantity"
                         name="Quantity"
                         maxlength="16"
                         min="0"
                         step="1"
                         value="{!v.newItem.Quantity__c}"
                         required="true"/>
        <lightning:input type="number" aura:id="itemForm" label="Price"
                         name="Price"
                         min="0"
                         step=".01"
                         value="{!v.newItem.Price__c}"
                         formatter="currency"
                         messageWhenRangeUnderflow="Enter an amount that's at least .01."/>
        <lightning:input type="checkbox" aura:id="itemForm" label="Packed?"  
                         name="Packed"
                         checked="{!v.newItem.Packed__c}"/>
        <lightning:button label="Create Expense" 
                          class="slds-m-top--medium"
                          variant="brand"
                          onclick="{!c.clickCreateItem}"/>
    </form>
  </fieldset>
  <!-- / BOXED AREA -->

</div>
        </lightning:layoutItem>
    </lightning:layout>
</aura:component>
Hi,

I have made a fully working lightning application but the challenge wont accept it:(
Can anyone help me out?
The error is: The campingList component doesn't appear to have a Packed checkbox field in the form using a Lightning Base component.​
I clearly have the component however, and have searched the forum and found multiple people having the same issue.

Component
<aura:component >
    <aura:attribute name="newItem" type="Camping_Item__c" default="{ 'sobjectType': 'Camping_Item__c',
                    'Name': '',
                    'Quantity__c': '0',
                    'Price__c': 0,
                    'Packed__c': false}"/>

    <aura:attribute name="items" type="Camping_Item__c[]"/>

    <div class="slds-col slds-col--padded slds-p-top--large">
        <div aria-labelledby="newItemform">
            <fieldset class="slds-box slds-theme--default slds-container--small">
                <legend id="newexpenseform" class="slds-text-heading--small slds-p-vertical--medium">
                    Add Camping Item
                </legend>

                <form class="slds-form--stacked">
                    <div class="slds-form-element slds-is-required">
                        <div class="slds-form-element__control">
                            <lightning:input name="expname" label="Camping Item Name"
                                             class="slds-input slds-form-element__label"
                                             value="{!v.newItem.Name}" aura:id="expname"
                                             required="true"/>
                        </div>
                    </div>

                    <div class="slds-form-element slds-is-required">
                        <div class="slds-form-element__control">
                            <lightning:input type="number" label="Quantity" maxlength="10" min="1"
                                             name="quantity" class="slds-input slds-form-element__label"
                                             value="{!v.newItem.Quantity__c}" aura:id="quantity"
                                             required="true"/>
                        </div>
                    </div>

                    <div class="slds-form-element">
                        <div class="slds-form-element__control">
                            <lightning:input type="number" name="price" label="Price" formatter="currency" step="0.01" 
                                             class="slds-input slds-form-element__label"
                                             value="{!v.newItem.Price__c}" aura:id="price"
                                             />
                        </div>
                    </div>

                    <div class="slds-form-element">
                        <lightning:input type="checkbox" name="packed" label="Packed"
                                         class="slds-checkbox slds-form-element__label"
                                         aura:id="packed"
                                         value="{!v.newItem.Packed__c}"
                                         onchange="{!c.onChange}"/>                       
                    </div>

                    <div class="slds-form-element">
                        <lightning:button label="Create Expense"
                                          class="slds-button slds-button--brand"
                                          onclick="{!c.clickCreateItem}"/>
                    </div>
                </form>
            </fieldset>
        </div>
    </div>
    <section class ="slds-card__body">
        <div id="list" class = "row">
            <aura:iteration items="{!v.items}" var="item">
                <c:campingListItem item="{!item}"/>
            </aura:iteration>
        </div>
    </section>
</aura:component>


Controller
({
    clickCreateItem: function(component, event, helper) {
        // Simplistic error checking
        var validCamp = true;
        // get Value from expname input
        var textField = component.find("expname");
        console.log("--textField--"+textField);
        var textValue = textField.get("v.value");
        console.log('textValue = '+textValue);

        // get Value from quantity input
        var quantityField = component.find("quantity");
        console.log("--quantityField--"+quantityField);
        var quantityValue = quantityField.get("v.value");
        console.log('quantityValue = '+quantityValue);

        // get Value from price input
        var priceField = component.find("price");
        console.log("--priceField--"+priceField);
        var priceValue = priceField.get("v.value");
        console.log('priceValue = '+priceValue);

        // get Value from checkMark
        var checkmarkField = component.find("packed");
        console.log("--checkmarkField--"+checkmarkField);
        var checkmarkValue = component.get("v.newItem.Packed__c");
        console.log('checkmarkValue = '+checkmarkValue);

        // //TEST INPUT
        if ($A.util.isEmpty(textValue)){
            validCamp = false;
            textField.set("v.errors", [{message:"Camping Item name can't be blank."}]);
        }
        else {
            textField.set("v.errors", null);
        }
       
        if (validCamp == true && quantityValue < 1){
            validCamp = false;
            quantityField.set("v.errors", [{message:"Camping Item's quantity should be greater or equal 1."}]);
        }
        else {
            quantityField.set("v.errors", null);
        }
        priceField.set("v.errors", null);
        checkmarkField.set("v.errors", null);
        //
        // //LOGIC
        //
        if(validCamp){
        //
             var itemObj = component.get("v.newItem");
            itemObj.Packed__c = checkmarkValue;
             console.log("---itemObj---"+JSON.stringify(itemObj));
             console.log("Create camping item : " + JSON.stringify(itemObj));
             var theItems = component.get("v.items");
        
             // Copy the expense to a new object
        
             //var newItem = JSON.parse(JSON.stringify(itemObj));
             var newItem = itemObj;
             console.log("Expenses before 'create': " + JSON.stringify(theItems));
             theItems.push(newItem);
             component.set("v.items", theItems);
             console.log("Expenses after 'create': " + JSON.stringify(theItems));
             var newItemObj = {    'sobjectType': 'Camping_Item__c',
                                 'Name': '',
                                 'Quantity__c': 0,
                                 'Price__c': 0,
                                 'Packed__c': false};
             //resetting the Values in the form
             component.set("v.newItem",newItemObj);
             alert('the items value provider has changed');
        }
    },
    onChange : function(component, event, helper) {
               
        var packedBool = component.get("v.newItem.Packed__c");
        console.log('packedBool1 =', packedBool);
        if(packedBool === false){
            packedBool = true;
        } else {
            packedBool = false;
        }
        console.log('packedBool2 =', packedBool);
        component.set('v.newItem.Packed__c',packedBool);
        }
})
Trying the Input Data Using forms trailhead and doing the "Create a Form to Enter New Items" at the end of one module.  Getting error --

"Challenge Not yet complete... here's what's wrong: 
The campingList component doesn't have an attribute named 'newItem' of type Camping_Item__c with a default sObject."

MY campingList.cmp file begins--
<aura:component >
    
     <aura:attribute name="newItem" type="Camping_Item__c" default = "{ 'Quantity__c' : '0'
                                                                      , 'Price__c'   : '0' }"/>
     <aura:attribute name="items" type="Camping_Item__c[]"/>
Any Idea what could be wrong?

I am using a dev org with a Namespace.  (I thought you had to do do Lighning trailheads.)