Forums

Use JS to instantiate single field validation

symbal 17 Apr, 2014
Hi there,

Is there a way in which we can programmatically call validation on a specific field through Javascript?

I have a form which performs a username and email check http://mtn.transcend-intl.com/index.php/join-us on a current development site; the check itself goes great however, I would like to perform the Javascript validation prior to performing the GET call.

I'm not even sure what validation engine is being used here so and documentation on hooks is completely absent. Here's the snippet I use:


var intPass = 0;
$('#submit').attr('disabled', 'disabled');
$('#username').blur( function(e) {
        /* I WOULD LIKE TO CALL CHRONOFORMS VALIDATION HERE */

        var username = $('#username').val();
        if ( username != '' ) {

            var url = 'index.php?option=com_chronoforms&chronoform=ajaxcheck&username='+username+'&tmpl=component';
 
            $.get(url, function(data) {
                parseResult(data, 'username');
            });
        }
    });

    function parseResult(request, strElementID) {
        var objElement = $('#'+strElementID);
        objElement.removeClass('border-ok border-error');
        var msg = request.split('##@##');
        if(msg[0] === 'OK') {
            intPass++;
            objElement.addClass('border-ok');
            if(intPass == 2) {
                $('#submit').removeAttr('disabled');
            }
        } else {
            intPass--;
            $('#submit').attr('disabled', 'disabled');
            objElement.addClass('border-error');
        } 
    }
GreyHead 17 Apr, 2014
Hi symbal,

ChronoForms v4 uses the MooTools FormCheck library for validation - the docs are here

There is a FAQ that looks at adding a Loading button on form submit that shows you how to access the FormCheck submit event though I'm not sure that you need that.

I have a paid tutorial that looks at using Ajax to check an Email address so that functionality is similar, It uses the On Success event to change the CSS though, not to lock or un-lock the submit button.

Bob
This topic is locked and no more replies can be posted.