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

How can i pass extra parameter when color changed? #190

Open
jaydeeptops opened this issue May 28, 2019 · 7 comments
Open

How can i pass extra parameter when color changed? #190

jaydeeptops opened this issue May 28, 2019 · 7 comments
Assignees

Comments

@jaydeeptops
Copy link

jaydeeptops commented May 28, 2019

Hello

I want to pass some addition parameter like this when the color changed?

<color-picker` ng-model="account_type.type_color" options="options" event-api="eventApi(extraParameter)">

Can you please help me solve this issue?

Thanks

@ruhley
Copy link
Owner

ruhley commented May 28, 2019

@jaydeeptops See this example html and javascript for how to use the event api. Let me know if that helps you or not.

@ruhley ruhley self-assigned this May 28, 2019
@jaydeeptops
Copy link
Author

jaydeeptops commented May 29, 2019

@ruhley
I had already seen the examples but I didn't get an exact solution so I tried to post a question.
Let me brief about the scenarios.

In my project, I have 3 buttons of the color picker. As per event, I am getting which color selected in the onchange event but i need something to pass in the event api that which button type clicked. Like i have 3 buttons A, B, C. When color changed for A button then I want to pass type A in the onchange event. Can you please provide me a solution how can I pass it?

Thanks

@ruhley
Copy link
Owner

ruhley commented May 29, 2019

@jaydeeptops I think you would have to create separate event apis and do something like this

$scope.onChange = function (color, type) {
    console.log(color, type);
};

$scope.eventApiA = {
    onChange: function(color) {
        $scope.onChange(color, 'A');
    }
};

$scope.eventApiB = {
    onChange: function(color) {
        $scope.onChange(color, 'B');
    }
};

$scope.eventApiC = {
    onChange: function(color) {
        $scope.onChange(color, 'C');
    }
};

Let me know if that solves it for you.

@jaydeeptops
Copy link
Author

@ruhley Thanks for the solution. But is there any other solution to pass parameters in the function?

@ruhley
Copy link
Owner

ruhley commented May 29, 2019

@jaydeeptops Unfortunately not.

@jaydeeptops
Copy link
Author

@ruhley Thanks for the reply. I have implemented as you suggested.
I have one more question is there any button that I can put to save the color? Right now what happened I changed the color and it suddenly fires the onchange event of the apiEvent function. But I want to put one select button if the user confirmed which color he need then he clicked on save.

@ruhley
Copy link
Owner

ruhley commented May 30, 2019

In the click event of the other button you should be able to get the value from ng-model without using the onChange event - https://github.com/ruhley/angular-color-picker/blob/master/examples/01-simple.html#L254 and https://github.com/ruhley/angular-color-picker/blob/master/examples/app.js#L29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants