Problem with LiveValidation

monak83 20 Dec, 2011
Hi,
I have this form:
http://www.sgagrafica.com/index.php?page=shop.product_details&flypage=flypage_new.tpl&product_id=100&category_id=7&option=com_virtuemart&Itemid=126

On the first select I have 2 option (color RED) that are an OFFER.
I have done a LIVEVALIDATION for these option that the user can make an order only if the field SUPERFICIE (calculated by BASE*ALTEZZA) is more than 10.

Here my validation:

if ( (tipo=="10") || (tipo=="20") ) {
	//alert("sei dentro");
 window.addEvent('domready', function(){
  var valid = new LiveValidation('text_4');
  valid.add(Validate.Numericality, { minimum: 10, failureMessage: "NOOOOOOOOOO" });
  });
  }


This is the problem:
if i select a option that is not 10 or 20 (value)...I can make an order...ALL OK
if i select a option OFFERTA (10 or 20) and SUPERFICIE is minor than 10...Form il locked...ALL OK
if i select a option OFFERTA (10 or 20) and SUPERFICIE is maior than 10...I can make an order...ALL OK

NOW:

If I don't go forward to do an order and i would change the value of SELECT menu selecting another option (not OFFERTA so not 10 or 20 option value of select)...I should be able to make and order...but nothing...the form remains locked as if I have selected an option OFFERTA (10 or 20).

Where is the error in live validation code?
monak83 21 Dec, 2011
I'm testing and seems that once I have selected an option OFFERTA (value 10 or 20) the code (live validation) under IF steatement remains active eaven if I change the option value in that select.

Why?
Bob, can help me?

Regards and thanks so much for your wonderful works!!!

monak83
GreyHead 21 Dec, 2011
Hi monak83,

As far as I can see you are adding the validation if those options are selected - but you aren't removing them again if the validations are un-selected.

I never worked out how to remove a validation in LiveValidation (which is why I wrote the Hidden Inputs tutorial using the QuirksMode validation library and not LiveValidation). BUT 'polderguy' did post here recently that they and got the LiveValidation disable() and enable() functions to work after reading this post on StackOverflow. I haven't had time to follow up but this may help you.

Bob
monak83 21 Dec, 2011
Hi Bob,
I have read your link and I tried to this code:

if ( (tipo=="10") || (tipo=="20") ) {
	//alert("sei dentro");
 window.addEvent('domready', function(){
  var valid = new LiveValidation('text_4', {insertAfterWhatNode : "errore"});
  valid.add(Validate.Numericality, { minimum: 10, tooLowMessage: "Minimo 10 mq per i prodotti in OFFERTA" });
  });
  } else { 
  window.addEvent('domready', function(){
  var valid = new LiveValidation('text_4', {insertAfterWhatNode : "errore"});
  valid.remove(Validate.Numericality, { minimum: 10, tooLowMessage: "Minimo 10 mq per i prodotti in OFFERTA" });
  });
  }


the validation message works correctly: if I select value 10 or 20 the field SUPERFICIE must be maior than 10 and I see the error message, otherwise the error message doesen't appears eaven if the field SUPERFICIE is minor than 10.
The problem is that the forms remains loocked...why? Any Ideas?
GreyHead 22 Dec, 2011
Hi monak83,

If I have time this afternoon I'll take a look. I've spent hours on this in the past and am not too keen to get into the code again :-(

From tomorrow I'm away until 27 Dec - I will look when I am back if not before.

Bob
monak83 27 Dec, 2011
Thanks so much Bob, I will wait for a reply!
Regards
monak83
GreyHead 30 Dec, 2011
Hi monak83,

I've made some progress with this on a copy of your form . . . and then get stuck because the updatethis() function doesn't always run. I think that you have different code trying to use the same events :-(

Basically I think that you need to declare the params object for the validation and set up the validation once at the domready event
window.addEvent('domready', function() {
	var params = { 
		minimum: 10, 
		tooLowMessage: "Minimo 10 mq per i prodotti in OFFERTA" 
	};
	var valid = new LiveValidation('text_4', {
		insertAfterWhatNode : "errore"
	});
. . .

Then in the checking function turn the validation on and off with
	if ( (tipo == "10") || (tipo == "20") ) {
		valid.add(Validate.Numericality, params);
	} else {       
		valid.remove(Validate.Numericality, params);
	};

Bob
GreyHead 30 Dec, 2011
Hi monak83,

Please try removing the window.addEvent lines from the first block. There is an error showing because valid isn't defined.

var params = {
 minimum: 10,
tooLowMessage: "Minimo 10 mq per i prodotti in OFFERTA"
};
var valid = new LiveValidation('text_4', {
 insertAfterWhatNode : "errore"
});

Bob
monak83 30 Dec, 2011
dosen't works...the total amount is blank...and the validation for product OFFERTA not works!
GreyHead 30 Dec, 2011
Hi monak83,

Looks now as if 'text_4' isn't defined when that runs. You'll need to put back the window.addEvent lines and make sure that the 'updatethis' function only runs after 'valid' is defined.

Bob
monak83 30 Dec, 2011
Sorry Bob,
but I don't undestand...I have replaced the line
window.addEvent('domready', function() {
but dosen't works...how can I do?
This topic is locked and no more replies can be posted.