Add text pressing enter in field

Good morning,

I would like add the username to a line added in a field in the lightbox when this user press “Enter”.

Like this:

  • Refaire la penderie (Walter)
  • Équilibrer les comptes (Alain)
    -Retour sur la fiesse (Diane)

I’m using this code to accept “Enterkey” key and identify it but I don’t find the way to add the username by replacing “Enterkey” by “(Username)Enterkey”…

[code]
scheduler.getLightbox().onkeydown=function(e){
switch((e||event).keyCode){
case scheduler.keys.edit_save:
// Ajoute prenom user
if (event.keyCode)==‘13’){

				"Code should be here..."
				
				
			}
				if (!(e||event).shiftKey) return;
				scheduler.save_lightbox();
				break;
			case scheduler.keys.edit_cancel:

				scheduler.cancel_lightbox();
				break;
			default:
				break;
		}
	};[/code]

Hello.

Are you trying to change some field value?
In this case you could use formSection function and set new value using it.
See articles:
docs.dhtmlx.com/scheduler/api__s … ction.html
docs.dhtmlx.com/scheduler/lightb … ntrolvalue

thank you,

It’s perfect…

But one thing, how to know which section is active?
Because an “enter” in any field will create the new insert in the target one…

Thank’s.

Hello.

Each lightbox section has id. When enter is pressed you could get event target and try to find its id. You could go higher to parents (target.parentNode …) until find element with class “dhx_wrap_section”. It’s lightbox section wrapper. You could get its first child this id is the section id. Then you could iterate over sections and find section with this id.

Possibly something like this:

switch((e||event).keyCode){
			case 13:
				var target = e.target || event.srcElement;
				while(target && target.className != "dhx_wrap_section")
					target = target.parentNode;

				var sectId = target.firstChild.id;
				var sections = scheduler.config.lightbox.sections;
				var section = null;
				for(var i = 0; i < sections.length; i++){
					if(sections[i].id == sectId) {
						section = sections[i];
						break;
					}
				}

				if(section){
					//Do Stafff!..
					if(section.name == "description"){
						var descr = scheduler.formSection('description');
						var oldVal = descr.getValue();
						descr.setValue(oldVal + " (New text)");
						return false;
					}
				}
				break;
			default:
				break;
		}

Perfect!
Thank you sten!