View Full Version : How to find if a particular value exits in a data store using each method

13 Jun 2014, 1:32 PM
Hi All,

I have a editable combo box where I am getting the values from a data store. Now if a user types something in that combo box and clicks submit, I need to verify if that value exists in the store. I need to throw an alert in case if the value is not there. For this validation, I am getting the store and the value that the user typed in and trying to do the following.

if(item.data.referenceId == selectedReference ) {

so if the value is present in the store, it returns from the function and will continue with the rest of the validations, but if the value is not present I am getting a problem where it throws alert statement n number of times where n is the number of records in the store. I am not sure if I should be using the each method for my requirement. Can you please let me know if there is any other way of doing this or if I am missing something here.


13 Jun 2014, 2:01 PM

This is my first post in the forum and I hope that it helps :)

You could set combobox forceselection = true (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.form.field.ComboBox-cfg-forceSelection) to deny the user to set arbitrary text into the field.
Other solution is to use myStore.find(fieldName, valueToFind) (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-method-find) to find the index of the first matching Record in this store by a specific field value (it returns -1 if not match found).

Scott Mildenberger
13 Jun 2014, 2:13 PM
I think you want to use myStore.find().

15 Jun 2014, 8:56 PM
If(records.raw.yourfieldname === yourfieldvalue){

17 Jun 2014, 10:06 AM
Thanks a lot for the suggestion. I used find() and it solved my issue..