Set Listview checklist to required?

Is there's anyway to make a listview checklist required? so at least one item is checked?
I tried many ways but nothing worked. Even when I tried to make a custom validator I keep getting the error "TypeError: control.getSelectedItems is not a function
T'



5 Replies

SP Sowmiya Padmanaban Syncfusion Team March 20, 2020 10:14 AM UTC

Hi Ahmad,  
 
We have checked your reported query. We suspect that your requirement is to fetch the selected items count and perform the operations based on that.  
 
In ListView component, if you need to select the items on initial loading, you need to add the isChecked as true for particular LI Items. 

let checkboxdata: any = [ 
    { "text": "Hennessey Venom", "id": "list-01","isChecked": true }] 

If we want to fetch the details that number of items checked in ListView component. You can use getSelectedItems() method. Refer the below code snippet. 

 SelectedItems(): void { 
  var selecteditems = this.list.getSelectedItems() 
 } 

Refer the sample link below. 
 
To know more about the ListView component. Refer the below link. 
 
 
 
 
Please let us know, if you have need any further assistance. 
 
 
Regards,  
Sowmiya.P 



AA Ahmad Atallah March 20, 2020 01:32 PM UTC

Hi Sowmiya,
Thanks for your reply..

That's not exactly what I was asking for.. So I have a new screen with a Listview that have items.
Now, I want to add something like  Validators.required to the Listview.

I can add a function onSave to check if there's any item checked using getSelectedItems(), but I want it to work the same way validators work, so for example the save button won't be enabled without checking at least one item in the checklist.

Thank you again!


SA Shameer Ali Baig Sulaiman Ali Baig Syncfusion Team March 23, 2020 12:00 PM UTC

Hi Ahmad, 
 
Greetings from Syncfusion support. 
 
We have looked into your expected requirement with EJ2 ListView. For your information, we cannot use validation with ListView, since it is not a form component. But, we can achive your expected requirement in EJ2 ListView using its events and properties. 
 
 
To meet your expected requirement, we have prepared a simple sample, in which button with text as “submit” will only enable and work, if atleast one list item’s checkbox is in checked state. We have achieved this customization using the select and actionComplete events of the ListView component. 
 
Please, check the prepared sample below. 
 
 
Please, let us know if you need any further assistance. 
 
Regards, 
Shameer Ali Baig S. 



AA Ahmad Atallah March 23, 2020 02:48 PM UTC

Smart solution! thank you so much :)


SA Shameer Ali Baig Sulaiman Ali Baig Syncfusion Team March 24, 2020 03:33 AM UTC

Hi Ahmad, 
 
Welcome. Please, get back to us if you need any further assistance. We will be happy to assist you. 
 
Regards, 
Shameer Ali Baig S. 


Loader.
Up arrow icon