Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

JoomlaTune Support Forum    JComments component    General discussion    Topic: Field values cleared onload.
Pages: [1]   Go Down
  Print  
Author Topic: Field values cleared onload.  (Read 1499 times)
0 Members and 1 Guest are viewing this topic.
TGHI
Newbie
*

Karma: 0
Offline Offline

Posts: 3


« on: June 04, 2010, 02:24:40 »

Just a quick question.

I noticed that if I set a value in my comments template for one of the fields it gets cleared by *something* in jcomments-v2.1.js.  From what I can tell, it is referencing the name, website and email fields directly - changing the ids of the fields fixes my issue, but of course breaks everything else.  So, for example:

 
Code:
<input id="comments-form-name" value="Enter Your Name" name="name" type="text" size="22" tabindex="1" />

  Should display the name field with a value of "Enter Your Name" - but alas it is cleared when the page loads - as well as any styling I try to do on the fields themselves (specifically backgrounds).

Does anyone have any ideas for a workaround?  Any help would be appreciated.
Logged
TGHI
Newbie
*

Karma: 0
Offline Offline

Posts: 3


« Reply #1 on: June 04, 2010, 02:36:10 »

...alright nevermind, I figured it out.  For those looking for the solution on line 215 of jcomments-v2.1.js.

  init() tries to restore fields from a previous session (?)

Code:
init: function(id,editor){var f=this;this.id=id;this.form=this.$(id);this.editor=editor;this.events=new JCommentsEvents();this.setElements(new Array('name','email','homepage','title','comment'));this.restoreValues();this.clear('captcha');this.setCaptcha();},

So, I simply removed setElements() and restoreValues()

Code:
init: function(id,editor){var f=this;this.id=id;this.form=this.$(id);this.editor=editor;this.events=new JCommentsEvents();this.clear('captcha');this.setCaptcha();},

Seems to do the trick and the form still validates and submits just fine. 

Logged
smart
Administrator
Hero Member
*****

Karma: 160
Offline Offline

Gender: Male
Posts: 2559



WWW
« Reply #2 on: June 04, 2010, 13:46:19 »

You needn't remove setElements function because in this case after comment adding these fields wouldn't cleared and will contain entered data. So to enter new comment you'll need to clear text of previous comment.

If you don't want to save in browser cookies the name and email of the user - you could remove only restoreValues method. But more correct will be replace lines:

Code: (javascript)
storeValues: function(){for(var i=0;i<this.store.length; i++){try{var el=JComments.prototype.$(this.id+'-'+this.store[i]);if(el){JComments.prototype.setCookie(this.store[i],encodeURIComponent(el.value),14);}}catch(e){}}},
restoreValues: function(){for(var i=0;i<this.store.length; i++){try{var el=JComments.prototype.$(this.id+'-'+this.store[i]);if(el){if(el.type&&el.type=='hidden'){return;}else{el.value=decodeURIComponent(JComments.prototype.getCookie(this.store[i]));}}}catch(e){}}},
with
Code: (javascript)
storeValues: function(){},
restoreValues: function(){},
Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
TGHI
Newbie
*

Karma: 0
Offline Offline

Posts: 3


« Reply #3 on: June 04, 2010, 20:07:19 »

Aha...I see.  That does make sense too.  I haven't had any trouble with field values staying after submitting, but I guess it would make sense to remove the calls for saved data too.

Thanks for the suggestion.  Great component, too Smiley
Logged
smart
Administrator
Hero Member
*****

Karma: 160
Offline Offline

Gender: Male
Posts: 2559



WWW
« Reply #4 on: June 04, 2010, 20:09:13 »

In next version I'm going to add option to switch on/off storing these data into browser's cooike. So user will decide if he wants to store these data or no.
Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
Pages: [1]   Go Up
  Print  
JoomlaTune Support Forum    JComments component    General discussion    Topic: Field values cleared onload.
 
Jump to: