function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shivateja Madipalli 32Shivateja Madipalli 32 

Jquery .val() is giving undefined since Salesforce Spring'16 release

I have a Lighting app which was working fine, before Spring'16 release.

There were issues with Jquery 3.0 thus, downgraded to Jquery 2.2.4;  When I am trying to access html select element, it is giving undefined.

I am accessing html select element's selected value on 'onchange' event,
var selectedVal = $('#'+event.srcElement.id).val();

This is giving an error:

Something has gone wrong. Action failed: c$PsetComp$controller$permissionSetNamesddlChange [TypeError: undefined is not an object (evaluating 'options.length')]
Failing descriptor: {c$PsetComp$controller$permissionSetNamesddlChange}.
Please try again.


It is trying to access the length of options to find the selected value but as the element itself is undefined it is giving an error.

Same happened even when I have tried with html select element's id instead of event.srcElement.id

var selectedVal = $('#selectElementId').val(); 

The most interesting fact is, I am able to add options dynamically, i.e., there is no problem with accessing the html element but the issue is with accessing val();

      var fragment = document.createDocumentFragment();
      var opt = document.createElement('option');
      opt.innerHTML = "Chooseoption";
      opt.value = "Nothingelected";
      fragment.appendChild(opt);
      $('#permissionSetNamesddl').append(fragment);


 The above code isn't giving any error.

All of it was working fine before Spring'16 release.
Balasubramaniam 07Balasubramaniam 07
Hi shiva,

This might be due to Locker service, please deactivate lockerservices in critical updates and try again.

Thanks
Bala
Shivateja Madipalli 32Shivateja Madipalli 32
After speaking with SF customer service,

Every new Org which is created after Spring 2016 release will have Locker Services enabled for communities (at ORG Level) and for whole ORG (at SF level)

To disable Locker Services for whole Org, you need to speak with SF Customer Service, then you'll see an option in Critical Updates for disabling Locker Service for whole ORG.

For old orgs which were created before Spring'16 release will already have an option for disabling Locker Service for whole Org in Critical Updates.

All Managed Packages will not have any Locker Service enabled.

All the above are confined just for Spring'16 Release, everything will have Locker Service enabled from Winter'17 release.

What is with this Locker Service:

SF is increasing security by not allowing access of DOM element functionality like, .parent/innerHTML etc. (there are many) and all these features are enabled/disabled with Locker Service either at ORG level or SF level (dependent on org creation date)

There's **NO** best way around as SF will be removing the option of disabling Locker Service from Winter'17 release (Even at ORG level or SF level) from everything <<not sure with Managed Packages, need to find out>> and makes sure everyone use functionality provided by SF.

How can we access DOM in future?
 
SF is providing certain level of functionality by having its wrappers around it, they are adding/removing functionalities on daily basis, thus, there is no count of functionality yet. (Someone please add if you can find it)

Food for your brain:
https://developer.salesforce.com/blogs/developer-relations/2016/04/introducing-lockerservice-lightning-components.html

Lightning CLI:
https://releasenotes.docs.salesforce.com/en-us/summer16/release-notes/rn_lightning_cli.htm%20https://devcenter.heroku.com/articles/getting-started-with-nodejs#set-up

Guide:
https://developer.salesforce.com/docs/atlas.en-us.202.0.lightning.meta/lightning/cli_intro.htm
Rules:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/cli_rules.htm#cli_rules