Hello!
I have a combo box as a filter. To validate the entries I use onBlur event - I extract the Value of a selected option, and see if such option exists. That works fine. However, if the user selects a correct option, and then accidently creates any white spaces, like via tabbing, etc., the Value is now not returned, since Combo treats white space as a character, and therefore option is not found.
Here is my code:
function onBlurFunc(){
var combotext=z.getComboText();
var value = z.getActualValue();
if( !this.getOption(value)){
MY VALIDATION CODE
}else{}
Is there any way that Combo can not treat white spaces as a character, or that the line “var value = z.getActualValue();” ignores the white spaces?
Thank you a lot!
Anya
Hello,
I think it would be better to consider this case in your code if it is needed.
combo.attachEvent("onBlur", onBlurFunc);
function onBlurFunc(){
var combotext=z.getComboText();
var value = z.getActualValue();
if( !this.getOption(value)){
value = value.replace(/(^[ \t]*)|([ \t]*$)/g, "");
if(!this.getOptionByLabel(value)){
// validation
}
}
}
Hello Alexandra!
In my case, value is numeric, so that when users change values in Combo box, this line "
var value = z.getActualValue();" returns a number (index of the option). Therefore it is not possible to run this lines:
var value = z.getActualValue();
if( !this.getOption(value)){
value = value.replace(/(^[ \t])|([ \t]$)/g, “”);
Is this correct that getActualValue returns the index in my case? If yes, how can I deal with empty spaces in this scenario?
Thank you!
I’ve actually trimmed the combotext value:
combotext = combotext.replace(/(^[ \t])|([ \t]$)/g, “”);
And then check if this exists:
if(( !this.getOptionByLabel(combotext)
This seems to work. The only thing I am not sure about - even when I trim combotext, the value of the field is then left not as an index, by as a string. When I tab back to this option, all is corrected and the value is turned back to index. I am not sure at this point what kind of complications I will get later.
Hello,
getActualValue returns either option value (key) or the text in header if there is not an option that corresponds it.
this line “var value = z.getActualValue();” returns a number (index of the option)
There won’t be empty spaces if the value is a number and you should not call replace method for it.
If it is needed you can add a check for value type
if(typeof value == “string”)
value = value.replace(/(^[ \t])|([ \t]$)/g, “”);