EasyUI Forum
May 17, 2024, 09:34:13 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Validate Combobox Options [Solved]  (Read 10287 times)
Darrel
Jr. Member
**
Posts: 74


View Profile
« on: June 17, 2016, 07:22:03 AM »

Hello,

I'm having a select box which gets the data to be displayed as option tags using an ajax call. I then initial the select box with the easyui combobox. The code for the same is given below:

Code:
opt_str = "";  //value comes from the ajax call

$('#select').html(opt_str);

//tried using this but it is giving me the old value and new value.
$('#select').combobox({
onChange: function(newValue, oldValue){
alert("newValue: " + newValue + "\noldValue: " + oldValue);
}
});


I want to ensure that the value entered by the user in the editable combobox is present in the dropdown list after the user has tabbed out from the combobox or the combobox has lost the focus. I want to compare the text with the value of the combobox. If the value is not present in the list then an error message will be shown to the user. How can I achieve the same??

Thanks in advance...

Regards,
Darrel
« Last Edit: June 20, 2016, 12:10:20 AM by Darrel » Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #1 on: June 17, 2016, 07:29:19 AM »

Please refer to this topic http://www.jeasyui.com/forum/index.php?topic=3364.msg7623#msg7623
Logged
Darrel
Jr. Member
**
Posts: 74


View Profile
« Reply #2 on: June 17, 2016, 07:43:28 AM »

Thanks jarry for your quick reply.

Is there anyway in which I can focus on the control again, if the value is not proper? Also please could you tell me how to retrieve the value of the option tag as well using combobox.

Thanks.
Logged
Darrel
Jr. Member
**
Posts: 74


View Profile
« Reply #3 on: June 20, 2016, 12:09:58 AM »

Hello,

I was able to access the value of the drop down using the following line of code inside the for loop:

Code:
var dropdown_value = data[i]["value"];

To achieve my validation requirements, I added a global boolean variable g_bln_validValue and used it as a flagging value. If the flag is true, then the value is present in the drop down list. I then check the value if the flag in my function loadPageData. The modified code is as follows:

Code:
g_bln_validValue = false;		//added at the top in my html page code

$.extend($.fn.validatebox.defaults.rules,{
inList:{
validator:function(value,param){
var c = $(param[0]); //param[0] = field id
var opts = c.combobox('options');
var data = c.combobox('getData');
var exists = false;
for(var i=0; i<data.length; i++)
{
//if (value == data[i][opts.textField])
if (value.toLowerCase() == data[i][opts.textField].toLowerCase())
{
exists = g_bln_validValue = true;
g_str_dropDownValue = data[i][opts.textField];

var dropdown_value = data[i]["value"];

//console.log("value.toLowerCase(): " + value.toLowerCase() + "\tdata[" + i + "][opts.textField].toLowerCase(): " + data[i][opts.textField].toLowerCase() + "data[" + i + "][\"value\"]: " + data[i]["value"]);

loadPageData();
break;
}
}

g_bln_validValue = exists;

return exists;
},
message:'invalid value.'
}
});

Thanks & Regards,
Darrel.
Logged
anugrast
Jr. Member
**
Posts: 52


View Profile Email
« Reply #4 on: October 02, 2016, 08:00:15 PM »

How could we modify this to work with a pre-existing value in Edit Mode? Because I always get error when in Edit Mode...

Thx
Logged
Darrel
Jr. Member
**
Posts: 74


View Profile
« Reply #5 on: October 06, 2016, 04:02:02 AM »

Hello anugrast,

Please could share some code that you've done so far, so that I would be able to understand your scenario better. If possible could you add it in as a reloado code using the following url: http://code.reloado.com

Regards,
Darrel
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!