Listbox should not be empty

Posted by: nivishapanwar on 22 February 2021, 5:12 pm EST

    • Post Options:
    • Link

    Posted 22 February 2021, 5:12 pm EST

    Hello,

    I am using a wijmo listbox . In that I am using add, remove , update functions.

    How can i restrict the listbox to be not empty, means there should be always a record present in listbox.

    removeRecord() {

    let lb = this.ListData.collectionView;

    lb.items.splice(this.ListData.selectedIndex, 1);

    lb.refresh();

    this.ListData.selectedIndex = -1;

    this.fullname = “”;

    this.saveListBoxData();

    }

    displayListBoxValueInTextField(listBox) {

    this.fullname = listBox.selectedValue;

    }

    Thank you.

    Regards,

    Nivisha Panwar

  • Posted 22 February 2021, 9:51 pm EST

    Hi Nivisha,

    You can add a check initially whether at least one item is present or not:

    removeRecord() {
    	let lb = this.ListData.collectionView;
    	if(lb.totalItemCount <= 1) {
    		return;
    	}
    	.....
    }
    

    Regards,

    Ashwin

  • Posted 28 February 2021, 10:31 pm EST

    Hi Ashwin,

    I tried using this, but it gave an error that totalitemcount property doesn’t exist in collection view.

    Then I tried with ._src.length but still got the same error.Can you suggest something else?

    Thank you.

    Regards,

    Nivisha

  • Posted 1 March 2021, 10:55 pm EST

    Hi Nivisha,

    This type of error is not thrown by JS. If the totalItemCount property is not present in CollectionView, then it will return undefined and will not produce this error. So, please make sure that this.ListData.collectionView is actually an instance of CollectionView.

    You can also use items.length or sourceCollection.length property.

    ~regards

  • Posted 1 March 2021, 11:03 pm EST

    Hi Ashwin,

    Thanks for the help, sourceCollection.length property worked.

    Regards,

    Nivisha

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels