4

The <lightning-input type="search"></lightning-input> has the is-loading attribute that puts a little spinner in it 'when data is loading'.

For my search input, I call out to Apex with the search term and return record that match or partially match the search term with their name. However, I cannot find a way to turn this is-loading on and off. I am not seeing how you dynamically toggle this attribute.

I am wanting to do something like:

this.isLoading = true;
searchObjects({objectType: this.objectType, phrase: searchPhrase})
            .then(result => {
                this.results= JSON.parse(result);
                this.isLoading = false;

            }).catch(error => {
                this.isLoading = false;
                //show error
            });

Where isLoading will toggle the is-loading attribute of the input. Is this possible?

1
  • Just tested this, and yes, it should work. Your problem might be elsewhere. Can we see more code?
    – sfdcfox
    Commented Feb 24, 2020 at 20:04

1 Answer 1

6

You just need to set the attribute, then you can toggle it. Example.

<lightning-input label="Search" is-loading={isLoading} type="search"></lightning-input>

...

@track isLoading = false;

...

this.isLoading = true;
searchObjects({objectType: this.objectType, phrase: searchPhrase})
            .then(result => {
                this.results = result;
            }).catch(error => {
                //show error
            }).finally(() => this.isLoading = false);    
1
  • Oh nice. I couldn't find an example of actually setting it, only it existing in the component to indicate it was loading. Then I was playing around in the playground by setting it to "false" in the HTML and it didn't do anything, the spinner was still there, so assumed it couldn't be set. Then when I tried your example with the @track it works. A bit confusing, but at least it works this way. Thank you. Commented Feb 24, 2020 at 20:20

You must log in to answer this question.

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