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

update ngModel value without the need to click 'select' button #95

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dist/mdColorPicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ md-color-picker .md-color-picker-input-container .md-color-picker-clear,
}
.md-color-picker-container .md-color-picker-preview {
-webkit-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
font-weight: bold;
Expand Down
13 changes: 11 additions & 2 deletions dist/mdColorPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

var dateClick;

var colorDelta;

var canvasTypes = {
hue: {
Expand Down Expand Up @@ -523,6 +523,13 @@ angular.module('mdColorPicker', [])
updateValue(newVal);
});

// Real time update on ngModel value
$scope.$watch(function () {
return colorDelta;
}, function () {
$scope.value = colorDelta;
});

// Watch for updates to value and set them on the model
$scope.$watch('value',function(newVal,oldVal) {
if (newVal !== '' && typeof newVal !== 'undefined' && newVal && newVal !== oldVal) {
Expand All @@ -533,7 +540,7 @@ angular.module('mdColorPicker', [])
// The only other ngModel changes

$scope.clearValue = function clearValue() {
$scope.value = '';
ngModel.$setViewValue('');
};
$scope.showColorPicker = function showColorPicker($event) {
if ( didJustClose ) {
Expand Down Expand Up @@ -717,6 +724,7 @@ angular.module('mdColorPicker', [])
$scope.setValue = function setValue() {
// Set the value if available
if ( $scope.color && $scope.color && outputFn[$scope.type] && $scope.color.toRgbString() !== 'rgba(0, 0, 0, 0)' ) {
colorDelta = tinycolor( $scope.color );
$scope.value = $scope.color[outputFn[$scope.type]]();
}
};
Expand Down Expand Up @@ -899,6 +907,7 @@ angular.module('mdColorPicker', [])
//console.log( "DIALOG CONTROLLER OPEN", Date.now() - dateClick );
$scope.close = function close()
{
colorDelta = options.value;
$mdDialog.cancel();
};
$scope.ok = function ok()
Expand Down
Loading