-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Fixes formly-js#26
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,14 @@ export default ngModule => { | |
valueProp: c.string.optional | ||
}) | ||
}, | ||
defaultOptions: { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
kentcdodds
|
||
ngModelAttrs:{ | ||
required: { | ||
attribute: '', | ||
bound: '' | ||
} | ||
} | ||
}, | ||
apiCheckInstance: c, | ||
controller: /* @ngInject */ function($scope) { | ||
const to = $scope.to; | ||
|
@@ -23,15 +31,42 @@ export default ngModule => { | |
change: setModel | ||
}; | ||
|
||
function checkValidity(expressionValue){ | ||
var valid = angular.isArray($scope.model[opts.key]) && | ||
$scope.model[opts.key].length > 0 && | ||
expressionValue; | ||
|
||
$scope.fc.$setValidity('required', valid); | ||
} | ||
|
||
function setModel() { | ||
$scope.model[opts.key] = []; | ||
angular.forEach($scope.multiCheckbox.checked, (checkbox, index) => { | ||
if (checkbox) { | ||
$scope.model[opts.key].push(to.options[index][to.valueProp || 'value']); | ||
} | ||
}); | ||
|
||
// Must make sure we mark as touched because only the last checkbox due to a bug in angular. | ||
$scope.fc.$setTouched(); | ||
checkValidity(true); | ||
} | ||
|
||
if(opts.expressionProperties && opts.expressionProperties.required){ | ||
This comment has been minimized.
Sorry, something went wrong. |
||
$scope.$watch($scope.options.expressionProperties.required, function(newValue){ | ||
checkValidity(newValue); | ||
}); | ||
} | ||
|
||
if($scope.to.required){ | ||
var unwatchFormControl = $scope.$watch('fc', function(newValue){ | ||
if(!newValue){ return; } | ||
checkValidity(true); | ||
unwatchFormControl; | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
}; |
1 comment
on commit 08d4fbe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. I would be curious about the required
and ng-required
attributes as a means to improve the "hack." Also, if you're keen, I'm a big fan of Newspaper Code Structure :-) You've mostly got it.
Thanks for working on this!
This was done to prevent ngModelAttributesTemplateManipulator from adding ng-required or required attributes.