开发者

how to do a javascript validation in joomla backend

How to do a java script validatio开发者_运维百科n in joomla?


Same was as on the Front-End, by using JHTML::_('behavior.formvalidation');

Here is Joomla's tuturial for adding validation. Only difference is that you will have to copy the CSS for invalid class, it highlights the textboxes when values are not valid.

Also, my personal preference. Instead of coding the <form ... onsubmit="return jsFunction()"> I like to do it like this:

<script type="text/javascript">

window.addEvent('domready', function(){

// Add submit event to the form
$('myForm').addEvent('submit', function(e){
    // Default check
    var isValid = document.formvalidator.isValid(frm);

    // Do additional checks + create message
    var msg  = '';
    if (!isValid){
        msg = 'Some values are not acceptable. Please retry.';
    }else if($('some-other-value').value == 0){
        msg = 'Select IO';
        isValid = false;
    }

    if (!isValid){
        // Stop event
        new Event(e).stop();

        // Somekind of invalid form handler... can do effects in here, etc...
        handleInvalidForm(this, e, msg);
    }

    //
    return isValid;
});


});

</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜