JqueryArtifacts doesn't work if an element has a "." in the id

19 views
Skip to first unread message

Austen Holmes

unread,
May 13, 2016, 12:01:52 PM5/13/16
to Lift
Hi,

We're transitioning an app from an older maintenance version of lift to the latest RC.  At some point, we made the mistake of using element ids with a "." in them.  Causes all sorts of annoyance in css, jquery, etc, but we have a lot of dynamic pages and existing code built this way.  Well, with event handlers being extracted via onEvent and moved to page-level javascript (a good thing, :) ), liftJQuery doesn't escape the id, even though it's technically allowed.  For example, we can use $("#first\\.last").

Is this something that should be fixed?
Is there a way to override the onEvent handler in the meantime for lift jquery artifacts?

Thanks,

-Austen

Tim Nelson

unread,
May 13, 2016, 1:17:29 PM5/13/16
to Lift
Hi Austen,

I think finding a solution for that is a good idea.

In the meantime, you can override onEvent using the following:

In Boot.boot add:

LiftRules.javaScriptSettings.default.set(() => () => Empty)


That stops Lift from sending the JavaScript that configures lift.js using LiftRules.

Add the following JavaScript to your page:

var opts = {
  onEvent
: function(elementOrId, eventName, fn) {
   
if (typeof elementOrId === 'string') {
      elementOrId
= '#' + elementOrId;
   
}


    jQuery
(elementOrId).on(eventName, fn);
 
}
};


var lift_settings = $.extend({}, liftJQuery, opts);


lift
.init(lift_settings);


You'll need to add any LiftRules settings that you need to override to the opts object.

Tim

Austen Holmes

unread,
May 13, 2016, 3:03:24 PM5/13/16
to Lift
Great, that's what I was looking for.

Thanks!
Reply all
Reply to author
Forward
0 new messages