3

I have jquery bundle:

bundles.Add(new ScriptBundle("~/bundle/jquery").Include(
                ScriptsPath("jquery-2.0.3.js"),
                ScriptsPath("jquery.validate.js"),
                ScriptsPath("jquery.validate.unobtrusive.js"),
                ScriptsPath("jquery-ui-1.10.3.js"),
                ScriptsPath("jquery.validate.unubtrusive.config.js"),
                ScriptsPath("jquery.easing.1.3.js "),
                ScriptsPath("jquery.unobtrusive-ajax.min.js"),
                ScriptsPath("jquery.validate.custom.attributes.js") ...

On user registration page I have both login and register forms so form inputs have Register. and Login. prefixes in their names. Basically it looks like:

<input type="text" ... id="Register_Email" name="Register.Email" />
<input type="password" ... id="Register_Password" name="Register.Password" />

When I publish my application in release mode i get this error in bundle file:

uncaught jquery error in bundle file

This is obviously because of the dot in input's name. How can I save the dot and fix this issue? I've already tried to BundleTable.EnableOptimizations = false; but it didn't help and I do not consider this as appropriate solution because it annihilates the purpose of the bundle. Also note that issue takes place only in Release mode.

EDITS: Bundle file list contains one script file of my own, it contains client side validation logic for my ForbidHtmlAttribude:

jquery.validate.custom.attributes.js

jQuery.validator.unobtrusive.adapters.add(
    'forbidhtmlattribute',
    ['htmlregexpattern'],
    function (options) {
        options.rules['forbidhtmlattribute'] = options.params;
        options.messages['forbidhtmlattribute'] = options.message;
    }
);

jQuery.validator.addMethod('forbidhtmlattribute', function (value, element, params) {
    if (value === null || value === undefined) return true;

    var regex = params['htmlregexpattern'];
    return !value.match(regex);
}, '');
Dmytro
  • 16,668
  • 27
  • 80
  • 130
  • Do you have your own (not jQuery) script file(s) in the same bundle? – Alexander Dayan Apr 19 '15 at 21:35
  • Before u start digging around, why don't you try an underscore, and replace it later in ur code with a dot. Or try another bundling tool. – Legends Apr 19 '15 at 21:38
  • @AlexanderDayan, only one - `jquery.validate.custom.attributes.js`, it contains client side validation logic for my `ForbidHtmlAttribude`. There are no broken selectors like `:input[name=Register.Password]` – Dmytro Apr 19 '15 at 21:43
  • 1
    @Legends, dot is placed by mvc framework html helper: `ViewData.TemplateInfo.HtmlFieldPrefix = "Login";` , `@Html.TextBoxFor(m => m.Email)` , I showed already rendered html – Dmytro Apr 19 '15 at 21:45
  • I'm almost sure what is your problem, but I need to see your script code. – Alexander Dayan Apr 19 '15 at 21:48
  • @AlexanderDayan. I've added the script code to the question – Dmytro Apr 19 '15 at 21:51
  • Sorry, I thought u put it there by urself, never used MVC – Legends Apr 19 '15 at 21:52
  • 1
    @Legends, there's no need to be sorry, thanks for trying to help. – Dmytro Apr 19 '15 at 21:53

1 Answers1

4

Most probably, the problem is in this line:

if (value === null || value === undefined) return true;

Try to change it to

if ((value === null) || (value === undefined)) return true;

Exaplanation:

MS minification algorithm removes unnecessary spaces. It 'knows' language keywords like "var' or 'return', but 'null' is not one of them. So, the minified line will be

if(value===null||value===undefined)return true;

Now from JavaScript point of view we have a strange variable named 'null||value'. Enclosing the conditions in the brackets solves the problem:

if(value===null)||(value===undefined)return true;
Alexander Dayan
  • 2,846
  • 1
  • 17
  • 30