0

i got this weird issue on happening only on IE8, 9, 10 and 11.

I wrote some jQuery validation code for telephone field on "admin/sales_order_create/index". This code worked as expected on Firefox. But on The IE it doesnt work until I refresh the page.

The jQuery seems to stop or conflict with the prototype, and that cause the prototype not load/ other js functions not to load.

here is my inline jQuery code loaded on app/design/adminhtml/default/default/template/widget/form/renerer/fieldset.phtml (it doesn't work even if I load as an external file).

how can I make this work on all IE or reload the page without manually reload the admin/sales_order_create/index, or add classes on the form in admin/sales_order_create/index

<script type="text/javascript">
    jQuery(document).ready(function(){
        <!--Enforce maximum of 15 characters-->
        jQuery("#order-billing_address_telephone").attr('maxlength','15');

        <!--ids we will be listening for when change takes place-->
        jQuery( "#_item1telephone, #order-billing_address_telephone" ).change(function() {
            <!--if the length on the number is morethan 15 characters, then alert and disable buttons-->
            if(jQuery(this).val().length > 15 ){
                jQuery('.save').addClass("disable");
                alert("Please do not enter more than 15 Telephone numbers. Adding more will results to failure of orders!");
            }
            else if(jQuery(this).val().length <= 15){
                jQuery(".save").attr("class","save");
            }
            <!--alphanumeric are not allowed on telephone-->
            if(!jQuery.isNumeric(jQuery(this).val()) ){
                jQuery('.save').addClass("disable");
                alert("Please use numbers only. Letters and spaces are not allowed.");
            }

    });
</script>
1

You need to do this The Proper Magento Way. Instead of adding some jQuery cruft to admin, simply change the existing validation to get it to work for you.

The validation is done with js/prototype/validation.js - a file you can extend in many ways.

For instance you could adjust the existing validation for telephone to get it how you want it. Or you could add in an extra validation class, editing the templates you use in admin accordingly.

Here is an old yet relevant inchoo article on how to do it:

http://inchoo.net/magento/out-of-the-box-form-validation-in-magento/

0

I can't say exactly why this is failing for you. It could be any number of issues, including the fact that prototype unfortunately suppresses many errors by using try/catch blocks in its framework code.

What I can suggest is to use core code or "Magento conventions" as much as possible to avoid stray issues. It would be better to use prototype's Validation class to re-write what you're trying to do:

Validation.addAllThese([
    [
        'validate-tel-length',
        'Please do not enter more than 15 Telephone numbers. Adding more will results to failure of orders!',
        function(value, object) {
            return value.length <= 15;
        }
    ]
]);

And then tag your target form fields with the validate-tel-length class.

In this validator callback, then, you could also toggle the .save element classes based on the return value.

Ref: http://blog.baobaz.com/en/blog/custom-javascript-form-validators

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.