Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Chris on Jul 21, 2008 05:03
open dhtmlx forum
Combobox input has to be a listed option

Hi,

I've got a couple of more questions about your brilliant combobox :)

Is there by any chance an option which makes it impossible to input a value into the combobox that doesn't exist in the drop-down list?
f.e. :
My list contains:
ID LABEL
1 word1
2 sentence1
3 letter1
4 number1
5 10
6 number 10
7 4
8 document1

If someone would enter 'word26' into the combobox and then leave the combobox it wouldn't find a value, but it doesn't clear the box!
And the wrong value it creates causes an error.
I know its possible to just check after the submit on my page, but I didn't want to let it go that far...

Question 2:
Using the same list as above:
If I enter '4' in the combobox, it returns ID nr 7 which is correct.
If i enter '3' it returns ID '3' to me and fills the combobox with 'letter1'
Is it possible NOT to have that last option?
My page re-filters itself after a selection in one of the comboboxes, creating less options for the next box.
(I've seen that you guys made an option for cascading boxes as well, but I don't understand it yet ;) )

Thanx in advance!
Answer posted by Support on Jul 21, 2008 06:33
>>Is there by any chance an option which makes it impossible to input a value
There is no such option.
Combo can be used in readonly mode, but it will function as native select in such case.
You can add next code
    combo.attachEvent("onChange",function(){
       if (combo.getActualValue()==combo.getComboText()) //non existing option entered{
          combo.setComboValue("");
          combo.setComboText("");
        }
       
    });


>>Is it possible NOT to have that last option?
You can change such logic only by code modification. But you can use onChange event and add any custom logic, which will change combo value|label after data selection.
Answer posted by Chris on Jul 21, 2008 07:02
Great thanx!

I used it like this and it works like a charm:

z.attachEvent("onChange",function(){
                   if (z.getActualValue()==z.getComboText()) //non existing option entered
                   {
                      frmModifyPlanning.combostatus.value='Reset';
                      z.setComboValue("-1");
                   }
                   else if (frmModifyPlanning.combostatus.value == 'Reset')
                   {
                         frmModifyPlanning.combostatus.value=''; 
                   }
                   else
                   {
                      frmModifyPlanning.refilter.value='Project';
                      frmModifyPlanning.submit();
                   }
                });