Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception occurred when checking element file, check the 'laravelValidation' method #135

Closed
adamtester opened this issue Feb 1, 2016 · 2 comments

Comments

@adamtester
Copy link
Contributor

Hello sorry but I have another issue (still researching the other one)

With file uploads I get the following error:

Exception occurred when checking element file, check the 'laravelValidation' method.

$("#new-info-form").validate({
    errorElement: 'span',
    errorClass: 'help-block error-help-block',
    errorPlacement: function(error, element) {
        if (element.parent('.input-group').length ||
            element.prop('type') === 'checkbox' || element.prop('type') === 'radio') {
            error.insertAfter(element.parent());
        } else {
            error.insertAfter(element);
        }
    },
    highlight: function(element) {
        $(element).closest('.form-group').addClass('has-error');
    },
    success: function(element) {
        $(element).closest('.form-group').removeClass('has-error');
    },
    focusInvalid: false,
    rules: {
        "client_id": {
            "laravelValidation": [
                ["Required", [], "The client id field is required.", true]
            ],
            "laravelValidationRemote": [
                ["Exists", ["client_id", "eyJpdiI6IlhJQTJ4NVd3UlwvT0s0azg5TW5nNDhRPT0iLCJ2YWx1ZSI6IlNzOTZ4MGdrbHpFQzdyN2tMQmR3RG9EeHpUQXYwYUltWFZBOUo3YWpNK1kxdjRMNlJoRkN0UnlQTDEzSERyMENQQ0Q1VlVRM0EyN0gycm51QXNFNzJ3PT0iLCJtYW2VkYTk2NjFjIn0="], "The selected client id is invalid.", false]
            ]
        },
        "file": {
            "laravelValidation": [
                ["Required", [], "The file field is required.", true],
                ["Mimes", ["pdf", "doc", "docx", "doc", "csv", "jpeg", "jpg", "gif", "png", "txt"], "The file must be a file of type: pdf, doc, docx, doc, csv, jpeg, jpg, gif, png, txt.", false]
            ]
        },
        "filename": {
            "laravelValidation": [
                ["Required", [], "The filename field is required.", true],
                ["Max", ["255"], "The filename may not be greater than 255 characters.", false]
            ]
        }
    }
});

I have this error on any page with a file upload, and it is either e or b:

Uncaught TypeError: e is not a function.  Exception occurred when checking element file, check the 'laravelValidation' method.
Uncaught TypeError: b is not a function. Exception occurred when checking element image, check the 'laravelValidation' method.
@adamtester
Copy link
Contributor Author

Found the cause, this seems to fix the issue (well bypass it) on line 3439

var lowerParams = params;
//var lowerParams = $.map(params, String.toLowerCase);
console.log(params);

outputs

["pdf", "doc", "docx", "doc", "csv", "jpeg", "jpg", "gif", "png", "txt"]

Can't seem to see what's wrong with that

@adamtester
Copy link
Contributor Author

Ok String.toLowerCase() is a firefox only thing so we need to change

var lowerParams = $.map(params, String.toLowerCase);

to

var lowerParams = $.map(params, function(item, index) {
    return item.toLowerCase();
});

See https://jsfiddle.net/hu62dx8h/4/ and https://jsfiddle.net/q15Lz501/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant