Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting slider value programatically #15

Open
BartaG512 opened this issue Apr 9, 2020 · 5 comments
Open

Setting slider value programatically #15

BartaG512 opened this issue Apr 9, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@BartaG512
Copy link

I would like to set the slider value programatically. Can i do this rightnow?

@RVenkatesh
Copy link
Owner

@BartaG512 Can you elaborate a bit more on this? It would be great if you can provide some code examples too.

@BartaG512
Copy link
Author

BartaG512 commented Apr 9, 2020

My use case that I have to update the slider's value from websocket updates.
I tried to pass a value variable into the component like this:

{{ember-slider value=sliderValue config=options}}

Then i updated sliderValue on the controller.
The slider value indeed changed. But slider handle did not follow it.

To achieve updating i had to extend the slider component, and use moveToPercentage method (in my example the min, max range is 0-100 so it is not a problem to use moveToPercentage method)

import EmberSlider from '@love-open-source/ember-slider/components/ember-slider'; //
import { observer } from '@ember/object';

export default EmberSlider.extend({
	init() {
		this._super(...arguments);
	},

	// eslint-disable-next-line
	setValueObs: observer('sliderValue', function() {
		this.moveToPercentage(this.get('sliderValue'));
	}),
});

Template:

{{extended-slider sliderValue=sliderValue config=this.options onChange=(action "onChangeAction") }}

This works but i guess observer is not the optimal solution for this.

I think the slider component should be changed that way, if you set the value, it should move the slider handle also.

@RVenkatesh
Copy link
Owner

@BartaG512 Agreed. The component with its current implementation assumes that the value will be once passed and further changed only by the component itself and not from the outside. I believe you are updating the value of your component from outside ( a new value from your web socket connection ).

We will add this capability sooner. While we do that, your extended slider is a good workaround.

@RVenkatesh RVenkatesh added the enhancement New feature or request label Apr 10, 2020
@BryanCrotaz
Copy link

This is really easy with Octane. Use https://github.com/pzuraq/tracked-toolbox and the @localcopy decorator. It will accept local changes and then overwrite them if the external args change

@RVenkatesh
Copy link
Owner

This is really easy with Octane. Use https://github.com/pzuraq/tracked-toolbox and the @localcopy decorator. It will accept local changes and then overwrite them if the external args change

Thanks @BryanCrotaz for suggesting. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants