Live validation basic question

rambb 15 Nov, 2010
Im trying to use the LiveValidation library included with Chronoforms, but i cannot get it working properly. In an HTML page this code is working:
<html>    <head>        <script type="text/javascript" src="livevalidation_standalone.js"></script>    </head>
    <body>
        <form action=""  method="post">
            <input type="text" id="one" name="uno" />
            <input type="submit" />
        </form>
        <script type="text/javascript">
            var f1 = new LiveValidation('one');
            f1.add(Validate.Presence);
        </script>  
    </body>
</html>


If i try the same thing inside a Chronoform Form i have the following JS error:

Uncaught Error: LiveValidation::initialize - No element with reference or id of 'text_1' exists!
FORM CODE
<div class="form_item">
  <div class="form_element cf_text"> <span class="cf_text">Chin Chun Chan</span> </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: ;">Click Me to Edit</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="text_1" name="text_1" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Submit" name="button_2" type="submit" id="submit" />
  </div>
  <div class="cfclear"> </div>
</div>

JAVASCRIPT CODE
     var f1 = new LiveValidation('text_1');
            f1.add(Validate.Presence);


what am i doing wrong?
GreyHead 17 Nov, 2010
Hi rambb,

You need to delay the execution of the JavaScript snippet until after the form HTML has loaded.

Bob
rambb 17 Nov, 2010
Thanks Bob, I got it working with
window.addEvent('domready', ....
.

I saw u wrote a document about LiveValidation and CF ( http://greyhead.net/how-to-docs/chronoforms-adding-custom-validations), before buying it I would like to know if there is any example in it about Validate.Custom function, because I cant make that LiveValidation's function work properly (something about an uncatched Livavalidation Exception/Error)


Another question, i saw with my code the error's div is displayed only when i edit the fields, and not when i just try to submit without editing (the submit fails but the div are not showing), while CF Validation's error's div is displayed both on submit and on blur. Why?
GreyHead 18 Nov, 2010
Hi rambb,

The How-to document doesn't look at Custom except to mention it. Most of the content is on Presence, Email and Format (using a Regular Expression).

There are LiveValidation settings for onlyOnSubmit and, I think, onlyOnBlur that control when the validation runs. These might give you what you need?

Bob
rambb 19 Nov, 2010
It's hard to find a solid example with Validate.Custom 😟

There are LiveValidation settings for onlyOnSubmit and, I think, onlyOnBlur that control when the validation runs. These might give you what you need?

the validation is running (i cant submit the form with invalid content), but the errors are not displayed onsubmit
GreyHead 19 Nov, 2010
Hi rambb,

By all means post the code here and I'll take a look.

Bob
rambb 21 Nov, 2010
Hi I've solved my Validate.Custom problem but I still dont understand why even in a simple form the LiveValidation doesnt display the
 <span class=" LV_validation_message LV_invalid">Can't be empty!</span>
onsubmit(but the form is not submitted if the field is empty), while the span is displayed onblur...

like i said in previous post, with built-in Chronoform validation the same SPAN is displayed both onsubmit and onblur

my empty test form:
<?php
$script = "
window.addEvent('domready', function() {
var f1 = new LiveValidation('text_1',{ validMessage: \"I am valid!\" });
f1.add(Validate.Presence);
})";
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration( $script );
?>

<div class="form_item">
  <div class="form_element cf_text"> <span class="cf_text">Test</span> </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="">text_1</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="text_1" name="text_1" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Submit" name="button_2" type="submit" id="submit" />
  </div>
  <div class="cfclear"> </div>
</div>



plugins:
all off
------------
validation:
enable validation: yes
run validation onlyonblur: no
run validation onlyonsubmit: no
This topic is locked and no more replies can be posted.