What I do is put the database ID into the HTML when the page is
generated, then I observe a container object and work out which
element to edit on the fly.
Here's a very old example, written back when Prototype 1.5 roamed the
earth. As Pascal famously put it, if I had more time, it would be
shorter:
if($('content_edit')){
Object.extend(Ajax.InPlaceEditor.prototype, {
onclickCancel: function() {
this.onComplete();
this.leaveEditMode();
this.dispose();
return false;
},
convertHTMLLineBreaks: function(string) {
return string.replace(/br[^]*/gi, \n);
}
});
$('main').observe('click',function(evt){
var what = Event.element(evt).up('div.edit');
if( what ){
var to_edit = what.id;
var index = what.id.replace('ed_','');
var editor = new Ajax.InPlaceEditor(to_edit,
'ajax_updater.php',
{callback: function(form, value) { return 'id='
+ index +
'class=contentcolumn=textvalue=' + encodeURIComponent(value) },
ajaxOptions: {
method: 'get',
onComplete: function(){
this.dispose();
}},
rows:15,cols:20
});
editor.enterEditMode('click');
}
});
}
Walter
On Dec 22, 2008, at 7:30 AM, Matt Andrews wrote:
If you choose to do it this way, I'd advise using a timestamp rather
than (or in conjunction with) the random string generator, just to
ensure it's definitely unique. Entropy's a bitch...
On Dec 22, 9:16 am, Calvin Lai cal...@gmail.com wrote:
Maybe you could write a random generator script that generates and
stores a
set of random letters and numbers, store it in a global array, and
keep
checking against that array every time you load a record from the
database.
Just make sure you insert the original record id into the
inplaceeditor
script as a parameter so it reaches the server-side file that
you're going
to use.
--
Calvin Lai
Business Developmenthttp://dealspl.us
On Mon, Dec 22, 2008 at 1:07 AM, Matt Andrews
mattpointbl...@gmail.comwrote:
You could just make your code into a function and pass the same php
variable as the parameter:
function newInPlaceEditor(itemID)
{
new Ajax.InPlaceEditor('title_'+itemID, '/demoajaxreturn.html',
{rows:
15,cols:40});
}
then your code:
div id='title_?php echo '$id'?'a href=javascript://
onclick='newInPlaceEditor(?php echo '$id'; ?'edit me/a/div
(not tested)
Matt
On Dec 20, 10:41 pm, Audg abe...@ccc.edu wrote:
Hi,
I was wondering if anyone could lend a hand with the fabulous
Ajax.InPlaceEditor script!
My question is this: Is there a way to generate an ID on the fly
that
would make the id unique?
Because I have a one-to-many situation with my database, there are
times when I'm displaying multiple records, which would result in
duplicate item ID's and confuse the script.
For example, One Author could have many book titles...but I don't
know
how many books the author has written until I query the
databaseso
I would need to create the id's on the fly.
I can make the div dynamic with php div id='title_?php echo
'$id'?'edit me/div
but is there a way to pass this same id to the new
Ajax.InPlaceEditor
to make it match?
script type=text/javascript
new
Ajax.InPlaceEditor('editme_THIS_WOULD_BE_A_UNIQUE_RECORD_ID', '/
demoajaxreturn.html', {rows:15,cols:40});
/script
Thanks for any help you can provide!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Prototype script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---