0

I am currently using ALV to validate forms on my visualforce page. As a result of visual force, all the ID's have colon's in them which I assume is causing the error

Uncaught Error: Syntax error, unrecognized expression: CreationPageBlock

on an id that looks like

CreationPage:CreationPageBlock:[otherthingshere]

Here is my code at the moment. I have tried various things from escaping the colon (using backslashes), to using getElementByID, to using the '[id='']' format, however I keep getting the same error every time I click anything on my visualforce page.

EDIT: Here is my updated code, still having the same issue however

$(function(){

    $('#CreationPage\\:CreationPageBlock\\:getOffering\\:troubleCode').alv();

});


<!--FormSubmit-->       
$('#CreationPage\\:CreationPageBlock\\:getOffering\\:getOfferingsButton').alv('validateForm',{
        formsToSubmit:'#CreationPage\\:CreationPageBlock\\:getOffering',
        formSuccess:function(){
            alert("SUCCESS");
        },
        formFail:function(){
            alert('MUCHFAIL');
        }
    });

EDIT#2: I understand this looks like a duplicate, but I have tried all the suggestions from the other posts but nothing seems to work which is why I posted the question here

Bacs
  • 919
  • 1
  • 10
  • 16
AlvinJ
  • 261
  • 4
  • 7
  • 20
  • You shouldn't even escape it. This naming convention isn't usual with IDs and you should avoid them at all times. –  Jun 25 '15 at 17:01
  • @asawyer not a duplicate, as I have tried those solutions as mentioned in my post. – AlvinJ Jun 25 '15 at 17:01
  • @Allendar yes I understand it isn't conventional, however visualforce pages force the ID's like that, and I cannot do anything to change it. – AlvinJ Jun 25 '15 at 17:02
  • Please show the exact failing code you tried based on the dupe, including the jQuery code--you only show the plain JS you tried. – Dave Newton Jun 25 '15 at 17:04
  • @DaveNewton That is all the code I am using. the '.alv' part of the code above is part of a library I am using called Apex Live Validation. The failure happens in my jquery.min file so it's hard to trace what is wrong there – AlvinJ Jun 25 '15 at 17:08
  • Don't develop with minifed libs for the exact reason you mentioned. – mccainz Jun 25 '15 at 17:10
  • 1
    Huh, I wouldn't have thought you could call jQuery functions off of plain JS `getElementById` results. – Dave Newton Jun 25 '15 at 17:10
  • @DaveNewton apparently so. In the documentation, this is how they say to set up validation. `$('#P100_LAST_NAME').alv();` – AlvinJ Jun 25 '15 at 17:20
  • @AlvinJ escaping the colon characters with a backslash will definitely work. If it's not working for you, post the code by which you're attempting it and somebody can probably help point out what you're doing wrong. – Pointy Jun 25 '15 at 17:22
  • @mccainz So I've learned my lesson and used the non min file. The error I'm getting is unsupported pseudo. – AlvinJ Jun 25 '15 at 17:22
  • @AlvinJ The \\ escape works fine, try $(...) instead of document.getElemenyById. http://jsfiddle.net/dauL13u2/ – asawyer Jun 25 '15 at 17:22
  • @AlvinJ right - that's because Sizzle is interpreting the `:` as a metacharacter. If you properly quote it with a backslash (and note that you'll need **two** backslashes in the strings), it won't do that. – Pointy Jun 25 '15 at 17:23
  • I am currently playing around with it, i'll report back if anything has changed. Thanks for the help – AlvinJ Jun 25 '15 at 17:30
  • I've updated my code, still same issue. Every time I click anything on the page, same error comes up. @Pointy – AlvinJ Jun 25 '15 at 17:40
  • @AlvinJ well as the fiddle linked by asawyer above shows, backslashes do work. Is it possible that there are some stray colons somewhere? You can add some `try ... catch` blocks to narrow down exactly where that exception is coming from. (It helps if you use non-minified versions of the libraries involved.) – Pointy Jun 25 '15 at 17:49
  • @Pointy i put try catches around my code but thats not the issue. The issue is with the jQuery library itself, on the blur event. I am not really sure what to do beyond this point – AlvinJ Jun 25 '15 at 18:07
  • @AlvinJ You can flag to reopen or write a new question with the additional information now that you've tried the other approach. – asawyer Jun 25 '15 at 18:10
  • @AlvinJ do the browser developer tools give you information as to *exactly* where the exception is being thrown? Again, using the un-minified version of jQuery makes that much, much easier. – Pointy Jun 25 '15 at 18:11
  • @AlvinJ That's a jQuery selector, not what you had in your original snippets. – Dave Newton Jun 25 '15 at 18:45

0 Answers0