EasyUI Forum
March 28, 2024, 06:30:22 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: Default Text value for combo, combobox, combogrid  (Read 14813 times)
phunksta
Jr. Member
**
Posts: 54


View Profile Email
« on: November 17, 2014, 08:18:38 AM »

Hi,

When loading a form containing any combo or extended combo like a combogrid, is it possible to set initial TEXT, not initial value?

In my use case, the database might return something like:
Code:
{"DealerID":"","DealerCode":"ABC?E"}

I would like to have a combobox that can be bound to the DealerID field on the form, but also refer to DealerCode.
When the DealerID is null on the record, but DealerCode is populated, I'd like the combo to treat the value returned by the DB in that field as if it were user input. This should then to go on to search the data etc. just like if the user had input it.

I have tried all sorts, but I can't find a way to make this behaviour happen!

I am imagining something like:

Code:
<input name="DealerID" class="easyui-combobox" data-options="textFieldName='DealerCode'" />

As a wanted side-effect, whatever is in the text field of the combo should post to the form field of that name.

Can anyone help with how I might achieve this?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: November 17, 2014, 07:06:03 PM »

When the form data is loaded successfully, search those combo components with empty values and then reset these fields with specified values.
Code:
$('#ff').form({
ajax:true,
onLoadSuccess:function(data){
var f = $(this);
var cc = ['combobox','combotree','combogrid'];
$.map(cc, function(c){
var combo = f.find('.'+c+'-f');
if (combo.length){
var opts = combo[c]('options');
var value = combo[c]('getValue');
if (!value){
combo[c]('setValue', data[opts.textFieldName]);
}
}
})
}
})
Logged
phunksta
Jr. Member
**
Posts: 54


View Profile Email
« Reply #2 on: November 20, 2014, 04:09:19 AM »

That looks great, I get the idea I think - after the form loads revisit the combos that did not get populated.

Can I clarify; If I use the setValue function on a combo(box|grid) but set for the Text value rather than the Id value, will the component understand this Ok?

EDIT: having tried this, the combogrid DOES show the text value after 'setValue', but also stores this value against its ID field. If this is submitted then this text value is submitted too causing a database failure.

I also tried:

Code:
    var $cb = $('#DealerID').combo();
    var $tb = $cb.combo('textbox');
    $tb.textbox('setValue',data[textFieldName]);

This shows the value, but it looks like it is being treated as a 'prompt' value rather than a real one.

So, I still can't see how to set the text value on a combo as if the user had entered it Sad
« Last Edit: November 20, 2014, 08:27:00 AM by phunksta » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: November 20, 2014, 07:15:12 AM »

The 'setValue' method allows the user to set the field value, which will be posted to the server. If the value exists in the drop-down list, the corresponding text will display on the combo component. If the value does not exist, the value itself will display on the combo component.
Logged
phunksta
Jr. Member
**
Posts: 54


View Profile Email
« Reply #4 on: November 20, 2014, 08:41:31 AM »

If the value does not exist, the value itself will display on the combo component.

If I can also then reset the actual ID field to empty/null I think this would work OK?

EDIT: or... when I submit the form I could modify the posted value, but is there an easy way to trap/identify a combo in the state as above?
EDIT2: During form submit I was able to put in direct checks on the form data, but it's not a very elegant solution Sad
Code:
if (frmdata.DealerID === frmdata.DealerCode) frmdata.DealerID = "";

« Last Edit: November 20, 2014, 09:16:17 AM by phunksta » 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!