Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by mahesh on Dec 08, 2009 16:02
open dhtmlx forum
dhtmlx schdeular & custom field on lightbox, can I move select items text automatically into the text descrition field?

I have a custom field on the lightbox corresponding to PROCEDURE similar to below:

var procedure=[
{key:180, label:" e.    task a        3 HOURS"},
{key:120, label:" f.    task b*         2 HOURS"},
{key:120, label:" g.    task c*        2 HOURS"},
{key:180, label:" i.    task d*     ADD 1 hr = 3 HOURS"},
]

What I would like to do is once one of these is selected, to place the text in quotes, or another field on the same line, automatically into the DESCRIPTION text box. Is this possible?
Answer posted by Alex (support) on Dec 09, 2009 02:12

You can try to redefine the set_value method of the select:

scheduler.form_blocks.select.set_value = function(node,value,ev){

    var txta = document.getElementsByTagName("textarea")[0];
    var selectEl = node.firstChild;
    selectEl.onchange = function(){
        var index = selectEl.selectedIndex;
        txta.value = selectEl.options[index].text;
    }
    node.firstChild.value=value||"";
}

Answer posted by mahesh on Dec 09, 2009 23:27

Alex,

  Thanks, that does work, although I am also trying to set the length of time automatically as well via using the value associated with a label.  Now the text is copied; I lose the setting of the end time.  I may just need to consolidate these routines.  My script follows if you have a change to look:

(function(){
   
   var end = null;
   var start = null;
   var mode = null;
   
   function set_end_time(){
    if (!mode.value) return;
    var time = scheduler.date.add((new Date(2000,1,1,0,start.value)),mode.value*1, "minute");
    end.value = time.getHours()*60+time.getMinutes();
   }
   
   var setter = scheduler.form_blocks.time.set_value;
   scheduler.form_blocks.time.set_value=function(node){
    var sels = node.getElementsByTagName("SELECT");
    
    start = sels[0];
    start.onchange=set_end_time;
    end = sels[4];
                                //Allow to free select time end
    //end.disabled=true;
    
    setter.apply(this,arguments);
    
    start.onchange();
   }
   
    var select = scheduler.form_blocks.select;
    scheduler.form_blocks.my_select = {
    get_value : select.get_value,
    set_value : function(node,value,ev){
   mode = node.firstChild;
   mode.value=value||"";
   mode.onchange=set_end_time;
   },
   render : select.render,
   focus : select.focus
   }
  })();

     //Add in selected procedure text into description field
     scheduler.form_blocks.my_select.set_value = function(node,value,ev){

    var txta = document.getElementsByTagName("textarea")[0];
    var selectEl = node.firstChild;
    selectEl.onchange = function(){
        var index = selectEl.selectedIndex;
        txta.value = selectEl.options[index].text;
    }
    node.firstChild.value=value||"";
}

Answer posted by Amit on Dec 10, 2009 00:01

For Setting the Value in TextArea We use,,,.................

 

 

var txta = document.getElementsByTagName("textarea")[0];
txta.value = selectEl.options[index].text;

 

but if I want to set the value in another Drop down...

then i am using,.....

 var txta = document.getElementsByTagName("select")[8];
    txta.innerHTML = "{key: sunday , label: Tomorrow}";

 

but this is not working...

can you tell me how i can set value in combo box...


 

Answer posted on Dec 10, 2009 01:31

Mahesh,

>> I lose the setting of the end time

There are two definitions of the set_value method of my_select object:

  scheduler.form_blocks.my_select = {
  get_value : select.get_value,
  set_value : function(node,value,ev){
...

and

  scheduler.form_blocks.my_select.set_value = function(node,value,ev){

Try to use one.

Answer posted by Alex (support) on Dec 10, 2009 01:34

Amit,

The  txta.innerHTML = "{key: sunday , label: Tomorrow}"; code can't be applied to the select element. In order to set a value you can use the next method:

 var someSelect = document.getElementsByTagName("select")[8];
someSelect.value = "sunday";