snChoiceList Directive snOnChange issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2018 05:32 AM
Hi All,
Need some Service Portal widget expertise please. I'm having trouble getting the value out of a sn-choice-list field with an onchange. Here's my HTML:
<sn-choice-list
sn-on-change="c.valueSelected(attribute)"
sn-model="attribute.value"
sn-items="attribute.choices"
sn-value-field="value"
sn-text-field="display">
</sn-choice-list>
And my client script:
c.valueSelected = function(attribute) {
alert(attribute.value);
};
alert(attribute.value) is giving me the oldValue rather than newValue - guessing it's some asynchronous thing. Anyone know how to get the newValue directly on a change?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2018 12:31 AM
I dig around this problem, as I could not afford to use either setTimeout or $watch and I found another way to access newValue in the onChange function. In short, you just add "selectedValue" argument to your function definition and also to arguments in sn-on-change.
In the end it would look like
<sn-choice-list
sn-on-change="c.valueSelected([otherArguments] , selectedValue)"
...>
</sn-choice-list>
c.valueSelected = function([otherArguments] , selectedValue) {
alert(selectedValue);
};
This is due to the way snChoiceList is implemented, and selectedValue is local containing passed to the execution of assigned function or something like this (sorry I do not know AngularJS very well yet 😛 )
Hope this helps someone in the future 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2020 02:24 AM
Hiii
If I want to bring [otherArguments] also in the client side.
then how should I code?