PDA

View Full Version : [SOLVED] Changing values of edit field before and after show



Barius
24 Aug 2007, 10:38 AM
What I want to do is to have an editable tree node that show the text 'Selected Pages: ##' when not being edited, but just shows the '##' when editing.

I have tried to change the values during 'beforestartedit' and again in 'beforecomplete' and also in 'complete'. Unfortunately, I cannot get the text displayed to change no matter what I do.

Here's an example of what I've tried so far:



ge = new xt.TreeEditor(ctree, {
allowBlank:false,
blankText:'Some text',
selectOnFocus:true
});

ge.on('startedit',function(boundEl,value){
if(ge.editNode.attributes.selectedPages){//Note: this is always true
var tmp = value.split(':');
ge.setValue(tmp[1]);
boundEl.value = tmp[1];
ge.editNode.text = tmp[1];
value = tmp[1];
return true;
}
});

ge.on('beforecomplete', function(myEditor, current, original){
if(ge.editNode.attributes.selectedPages){
myEditor.setValue('Selected Pages: '+current);
myEditor.value = 'Selected Pages: '+current;
ge.editNode.text = 'Selected Pages: '+current;
ge.editNode.attributes.selectedPages = current;
return true;
}
});

Barius
29 Aug 2007, 12:10 PM
I still haven't figured this out, does anyone have a clue?

Barius
29 Aug 2007, 4:16 PM
Well, no answers even after a few days :-/

Anyways, I figured out a solution myself, finally. I had to read the debug source though which was a bit of a headache. It's also a bit of a cludge, I still don't know why setValue doesn't change the text display when I believe it should. If a developer wants to comment it would be appreciated.

Here's the code that worked:

[CODE]
// create the editor for the component tree
ge = new xt.TreeEditor(ctree, {
allowBlank:false,
blankText:'A name is required',
selectOnFocus:true
});

ge.on('beforestartedit', function(myEditor,boundEl,startValue){
//note that 'this', 'myEditor' and 'ge' are all references to the same object
if(!this.editNode.attributes.allowEdit){
return false;
}
});

ge.on('startedit',function(boundEl,startValue){//no myEditor parameter, how odd...?
if(this.editNode.attributes.selectedPages){
var v = startValue.split(':');
this.setValue(v[1].strip());
}
});

ge.on('complete', function(myEditor, newValue, startValue){
if(this.editNode.attributes.selectedPages){
newValue = newValue.strip();//strip() is defined by Prototype
var v = newValue.split(':');
if(v[0] == 'Selected Pages'){ return; }

//For some reason, it is necessary to setText on the node directly. Using
//setValue on the editor does not change the text value.
//For some reason, the displayed value always resets to the startValue.
//Note that this is also the case if we use 'beforecomplete'.
this.editNode.setText('Selected Pages: '+newValue);

this.setValue('Selected Pages: '+newValue);
this.editNode.attributes.selectedPages = newValue;
}
});
[CODE]