1

I have a custom component that creates a new Task record. I use force inputField that is bound to a lookup field in Task.

I want to clear it's values if the user clicks cancel or save.


<div class="slds-form-element__row">
                <div class="slds-form-element slds-size--2-of-2">
                    <label class="slds-form-element__label" for="lookup-69">Project</label>
                    <force:inputField value="{! v.newTaskList.Project_Number__c}" aura:id="projId" class="sl"/>                          
                  </div>
                </div>

that's the force:inputfield that automatically binds to the Project Number field which is a look up to a standard object.

This is how it looks like in the fornt end

After I save the record, and go back to this lookup and remove the selected option, i get the error below.

enter image description here

That's why I want to clear the inputfield after i save the record. However, if you can also let me know your ideas as to why I am getting this error, it would be a big help. the work around i have is to refresh the whole page which is not good.

2 Answers 2

4

After toying with force:inputField a bit, I found the following code to clear it's value.

// Clear binded value
var contractLine = component.get('v.contractLine');
contractLine.Product__c = null;
contractLine.Product__r = {'sobjectType': 'Product2'};
component.set('v.contractLine', contractLine);    

// Clear product lookup
var productLookup = component.find('Product').get('v.body')[0];
productLookup.updateValues();
1

Just on click of button fir a method to controller and use the code as describe below- Here I am using attribute name as task

<aura:attribute name="task" type="task" description="The task object attribute" default="{
                              'sobjectType' : 'task',
                              'Subject' : '',
                              'Comments': ''
                             }"/>


var emptyTask = component.get('v.task');
  emptyTask.Subject = '';
  emptyTask.Comments = '';
  component.set('v.task', emptyTask);
2
  • The thing is, the inputfield is a lookup. if it was a plain textbox, assigning a '' value or null value would be fine. However, the way lightning has it, the lookup field has a pill that also has to be removed. Jul 7, 2017 at 7:52
  • Can you share a bit code here so that i can check how you are creating lookup? Jul 7, 2017 at 9:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .