Dear all,
I have decided to use the new Class function in the newest release of
Prototype (1.6) and re-write a function I currently have, reason been
for the simplicity to update it and to learn something new.
I wrote this bit of code:
var Comments = Class.create({
initialize: function(form) {
username = ''cmellor'';
this.form = form
},
// Post a comment
post: function() {
if(Spry.Widget.Form.validate(this.form) == true) {
new Ajax.Updater(''user_comments'',
''configs/ajax_functions.php?
profile_comment=post'', {
insertion: Insertion.Top,
parameters: {
user: username,
comment: $F(''comment'')
},
onLoading: function() {
$(''comment_button'').disable().value = ''Adding
Comment'';
$(''comment'').clear().disable()
},
onSuccess: function() {
$(''comment_button'').value = ''Comment
Posted'';
}
});
}
}
});
var comment = new Comments(''post-comment'');
I use the code in a form tag using an onsubmit behaviour, like so:
<form id="post-comment" onsubmit="comment.post(); return
false">
Something isn''t right about this, because I submit the form, it
refreshes and Firebug gives me the error "comment.post is not a
function"
Can somebody perhaps point out to me what I am doing wrong, any help
would be appreciated :)
Thank you,
- Chris.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Try this - I ran your code through JSLint, so not much magic on my
part:
var Comments = Class.create();
Comments.prototype = {
initialize: function(form) {
this.username = ''cmellor'';
this.form = $(form);
},
// Post a comment
post: function() {
if(Spry.Widget.Form.validate(this.form) === true) {
var xhr = new Ajax.Updater(''user_comments'',
''configs/
ajax_functions.php?profile_comment=post'', {
insertion: Insertion.Top,
parameters: {
user: this.username,
comment: $F(''comment'')
},
onLoading: function() {
$(''comment_button'').disable().value =
''Adding
Comment'';
$(''comment'').clear().disable();
},
onSuccess: function() {
$(''comment_button'').value =
''Comment Posted'';
}
});
}
}
};
The only major change I made is to use $() to make sure form is an
extended object, rather than a string.
Good luck!
On Nov 11, 8:03 pm, Chris
<cmel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Dear all,
>
> I have decided to use the new Class function in the newest release of
> Prototype (1.6) and re-write a function I currently have, reason been
> for the simplicity to update it and to learn something new.
>
> I wrote this bit of code:
>
> var Comments = Class.create({
> initialize: function(form) {
> username = ''cmellor'';
> this.form = form
> },
> // Post a comment
> post: function() {
> if(Spry.Widget.Form.validate(this.form) == true) {
> new Ajax.Updater(''user_comments'',
''configs/ajax_functions.php?
> profile_comment=post'', {
> insertion: Insertion.Top,
> parameters: {
> user: username,
> comment: $F(''comment'')
> },
> onLoading: function() {
> $(''comment_button'').disable().value =
''Adding Comment'';
> $(''comment'').clear().disable()
> },
> onSuccess: function() {
> $(''comment_button'').value =
''Comment Posted'';
> }
> });
> }
> }
> });
>
> var comment = new Comments(''post-comment'');
>
> I use the code in a form tag using an onsubmit behaviour, like so:
>
> <form id="post-comment" onsubmit="comment.post(); return
false">
>
> Something isn''t right about this, because I submit the form, it
> refreshes and Firebug gives me the error "comment.post is not a
> function"
>
> Can somebody perhaps point out to me what I am doing wrong, any help
> would be appreciated :)
>
> Thank you,
>
> - Chris.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Hey, Unfortunately that didn''t make any difference, I just get the same error in Firebug "comment.post is not a function" Thanks for helping! If anybody else has any idea on what my problem may be, I look forward to hearing from you! - Chris. On Nov 12, 1:36 am, TigerInCanada <tigerincan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Try this - I ran your code through JSLint, so not much magic on my > part: > > var Comments = Class.create(); > Comments.prototype = { > initialize: function(form) { > this.username = ''cmellor''; > this.form = $(form); > }, > // Post a comment > post: function() { > if(Spry.Widget.Form.validate(this.form) === true) { > var xhr = new Ajax.Updater(''user_comments'', ''configs/ > ajax_functions.php?profile_comment=post'', { > insertion: Insertion.Top, > parameters: { > user: this.username, > comment: $F(''comment'') > }, > onLoading: function() { > $(''comment_button'').disable().value = ''Adding > Comment''; > $(''comment'').clear().disable(); > }, > onSuccess: function() { > $(''comment_button'').value = ''Comment Posted''; > } > }); > } > } > > }; > > The only major change I made is to use $() to make sure form is an > extended object, rather than a string. > > Good luck! > > On Nov 11, 8:03 pm, Chris <cmel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Dear all, > > > I have decided to use the new Class function in the newest release of > > Prototype (1.6) and re-write a function I currently have, reason been > > for the simplicity to update it and to learn something new. > > > I wrote this bit of code: > > > var Comments = Class.create({ > > initialize: function(form) { > > username = ''cmellor''; > > this.form = form > > }, > > // Post a comment > > post: function() { > > if(Spry.Widget.Form.validate(this.form) == true) { > > new Ajax.Updater(''user_comments'', ''configs/ajax_functions.php? > > profile_comment=post'', { > > insertion: Insertion.Top, > > parameters: { > > user: username, > > comment: $F(''comment'') > > }, > > onLoading: function() { > > $(''comment_button'').disable().value = ''Adding Comment''; > > $(''comment'').clear().disable() > > }, > > onSuccess: function() { > > $(''comment_button'').value = ''Comment Posted''; > > } > > }); > > } > > } > > }); > > > var comment = new Comments(''post-comment''); > > > I use the code in a form tag using an onsubmit behaviour, like so: > > > <form id="post-comment" onsubmit="comment.post(); return false"> > > > Something isn''t right about this, because I submit the form, it > > refreshes and Firebug gives me the error "comment.post is not a > > function" > > > Can somebody perhaps point out to me what I am doing wrong, any help > > would be appreciated :) > > > Thank you, > > > - Chris.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
developer-P5Ep+WoDybrQT0dZR+AlfA@public.gmane.org
2007-Nov-12 03:16 UTC
Re: First Time Class User
If you change your onSubmit to "console.log(comment); return false"
what
do you get?
Also, I wouldn''t use the inline event handler. I''d add this
line to
your initialize function: (make sure you wrap form inside of $() first)
this.form.observe(''submit'', this.post.bind(this));
Then in your post function, have it accept an event parameter and add
event.stop() in it (to mimic your "return false" that you have in your
inline handler)
Chris wrote:> Dear all,
>
> I have decided to use the new Class function in the newest release of
> Prototype (1.6) and re-write a function I currently have, reason been
> for the simplicity to update it and to learn something new.
>
> I wrote this bit of code:
>
> var Comments = Class.create({
> initialize: function(form) {
> username = ''cmellor'';
> this.form = form
> },
> // Post a comment
> post: function() {
> if(Spry.Widget.Form.validate(this.form) == true) {
> new Ajax.Updater(''user_comments'',
''configs/ajax_functions.php?
> profile_comment=post'', {
> insertion: Insertion.Top,
> parameters: {
> user: username,
> comment: $F(''comment'')
> },
> onLoading: function() {
> $(''comment_button'').disable().value =
''Adding Comment'';
> $(''comment'').clear().disable()
> },
> onSuccess: function() {
> $(''comment_button'').value = ''Comment
Posted'';
> }
> });
> }
> }
> });
>
> var comment = new Comments(''post-comment'');
>
> I use the code in a form tag using an onsubmit behaviour, like so:
>
> <form id="post-comment" onsubmit="comment.post(); return
false">
>
> Something isn''t right about this, because I submit the form, it
> refreshes and Firebug gives me the error "comment.post is not a
> function"
>
> Can somebody perhaps point out to me what I am doing wrong, any help
> would be appreciated :)
>
> Thank you,
>
> - Chris.
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---