#jquery deprecation question

1 messages · Page 1 of 1 (latest)

sullen nymph
#

Hi, I am upgrading an old app from Ember 3.8 to 3.9. With this upgrade, ember-cli-update has upgraded @ember/jquery from 0.5.2 to 0.6.0. All of a sudden I am seeing errors saying Ember.$() has been deprecated, use import jQuery from 'jquery'. Anyone know why I'm getting this issue when I imported $ from jquery and am trying to do this.$('.foo')? Also this.$('.foo').datepicker from the jQuery ui library is undefined but if I do jQuery('foo').datepicker it doesn't come up as undefined.

livid widget
#

I'm also interestd in this. I'm trying to get a external script and Ember.$.getScripts it's working for me

restive pelican
#

most jquery libraries (that install things on the $ prototype), are going to work best with import $ from 'jquery', rather than the old, ember-integrated this.$

#

in components extending from @ember/component, if you need an element reference, I believe this.element is available to you

#

and then to use datepicker without your imported $, you'd do:

#

$(this.element).datepicker...

livid widget
#

Oh i got it

white trellis
restive pelican
#

straight from 3.8 to 3.12 then to 3.16.
clarification: these versions are "long term support" so the upgrade paths between tehse are smoother than going through each minor

livid widget
#

I actually just append a script tag to my document and it loads

sullen nymph
restive pelican
#

party I appear places

sullen nymph
#

Hi @restive pelican , this.$('.foo') used to just get that specific component's single element. That's now deprecated so if I do $('.foo') instead, it will get all elements with the foo class on the page. I guess this would be more of a jquery question, but any idea how I can just get the single element of the component instead of all on the page ? Bassically if I have multiple of that component on the page I will get an array of all those elements using $('.foo'), but I only want the one element in the component's hbs file

restive pelican
#

this.element.querySelector('.foo')?

sullen nymph
#

That will give me the element but won't work with datepicker since I think it's looking for a jquery object

restive pelican
#

right

white trellis
#

$ or jQuery takes a second argument with a context

restive pelican
#

but that can be passed to jquery

white trellis
#

jQuery('.foo', this.element) should work

restive pelican
#

oh nice, I didn't know it could do that

white trellis
#

@restive pelican Do you remember what version this.element arrived?

restive pelican
#

I thought you had to do $(this.element.querySelector('.foo'))

white trellis
#

the entire jquery api is permanently taking up space in my brain

sullen nymph
#

Ahh misunderstood, that works I think. Thanks again!

sullen nymph
restive pelican
white trellis