Hi all,
for 4 last days I was trying to get a staff that I''m sure is useful
for several of us.
I can''t solve it, so I''ll tell you it in this message, and I
hope we
can get a solution.
INTRODUCTION:
A typical approach to view & edit values (for a account settings, for
example) is show two different pages: one for viewing values, and the
other one for show a form to edit those values.
I think Ajax give us a good alternative so I want to get that with
only one page: User can see his/her account settings in one page, and
click on any value to display, dinamically, its edition field for
editing. Prototype does it with Ajax.InPlaceEditor object.
THE CODE:
The following code is for testing purpose, and emulates the
application behaviour in validation error case. So editMode must stay
enabled after click ok button when editMode is enabled.
In html file, Ajax.InPlaceEditor is declared by this way:
<div id="myDiv">This is a test</div>
<script type="text/javascript">
var myEditor = new Ajax.InPlaceEditor(''myDiv'',
''/myAction'',
{cols:40, evalScripts:1, rows:1});
</script>
''myAction'' script code return the following javascript code.
Header
content type is ''text/javascript'':
myEditor.myenterEditMode(''click'');
alert(''script finished'');
Alert instruction is only for debug, I''ll tell you about it later.
''myenterEditMode'' method is similar to enterEditMode. I had to
clone
it and deleted the initial checks to get function running when it be
called from the previous code.
So the code of ''myenterEditMode'' method is:
myenterEditMode: function(evt) {
this.oldInnerHTML = null;
this.saving = false;
this.editing = true;
this.onEnterEditMode();
if (this.options.externalControl) {
Element.hide(this.options.externalControl);
}
Element.hide(this.element);
this.createForm();
this.element.parentNode.insertBefore(this.form, this.element);
if (!this.options.loadTextURL)
Field.scrollFreeActivate(this.editField);
// stop the event to avoid a page refresh in Safari
if (evt) {
Event.stop(evt);
}
return false;
},
THE PROBLEM:
Page begins showing ''myDiv'' in view mode.
When you click it, it toggles to edit mode: value shows in its
editable form field with ''ok'' and ''cancel''
buttons.
After editing value (if you wish it), click ''ok'' button.
EditMode go off and go on again, but you can''t see the change.
Alert instruction show its debug message.
Click it.
And... editMode go off again. That''s the problem.
Alert is needed for view the change of state. Without it you can''t see
editMode enabled.
Maybe some code must be executed after alert instruction, or any
prototype behaviour goes editMode disabled again.
Anybody can help me to stay editMode enabled from ajax response
javascript code?
LATER:
In validation error case, ajax response javascript force to editMode
stay enabled and will show an error message over edition field.
I''ll write here any evolution finding out a solution for this problem.
Thanks in advance
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---