Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Minor
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.6
-
Fix Version/s: None
-
Component/s: Core CiviCRM
-
Labels:
-
Documentation Required?:None
-
Funding Source:Contributed Code
Description
There is an issue with the AngularJS crmEntityref directive where if you pass in multiple: true to the constructor the ui element fails to populate on page load. I've traced this issue to a problem in the directive:
ang/crmUi.js: 645 - On render the directive sets the value of the select2 widget using ngModel.$viewValue
For single value select2 boxes this isn't an issue but for multi-value widgets the select 2 library attempt to iterate over the value passed in and it becomes an issue.
The viewValue is always a string if the model is [1,2] the viewValue becomes "1,2" this would be fine if we were setting the value on a php page before load, but passing it into select2('val') causes it to be used as a dom selector.
see: https://github.com/colemanw/select2/blob/stable/3.5/select2.js#L3247
Some results:
[1,2]: works "1,2": fails "1": fails 1: works ["1", "2"]: works
One simple option would be to replace ngModel.$viewValue with ngModel.$modelValue (I've attached a patch for this)
Another would be to do some more complex legwork checking to make sure model values passed into a multi-value select2 widgets aren't simple strings, and if they are parse into some format that works. This second method would place a lot less work on someone creating an angular module (in theory), but seems to me like it could lead to problems down the road when we are doing "magic" that doesn't do what someone expects/wants.