I would like to have two menus, where the choice in the first menu sets the options in the second menu. This is to be done on a Salesforce VisualForce page that is using Angular JS and specifically the UI-Grid module for it. Similar controls are using the Angular button classes for menus, but I don't see how to dynamically set the choices using a button.
My current design is using a select control and ng-options.
In the controller.js I have declared variables to be used by the menus and a function to swap out the array values for the second menu. Note that $scope.fieldOptions is set through a query to Salesforce to pull option values from quicklist fields. This array is used in the UI-Grid filter option that accepts in a format like "[ { value: '1', label: 'male' }, { value: '2', label: 'female' }...".
$scope.editRows = 'all';
$scope.editField = 'Program';
$scope.editValue;
$scope.editOptions = {};
$scope.setEditOptions = function(editField) {
switch (editField) {
case "Program" :
$scope.editOptions = $scope.fieldOptions.Program_Enrolled__c;
break;
case "Appl. ASSET" :
$scope.editOptions = $scope.fieldOptions.Applied_for_ASSET__c;
break;
case "4 Year Degree" :
$scope.editOptions = $scope.fieldOptions.Has_Student_Completed_4_Year_Degree__c;
break;
}
}
On the VisualForce page I have the buttons defined in a button group with the select control just after.
<div class="row" style="margin-bottom:10px;">
<div class="col-md-12">
<div class="btn-group">
<div class="btn-group" dropdown="true" dropdown-append-to-body="true">
<button class="btn btn-default dropdown-toggle" dropdown-toggle="true" type="button">
{{editRows | capitalize}} Rows <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li ng-click="editRows = 'all'"><a href="#">All Rows</a></li>
<li ng-click="editRows = 'visible'"><a href="#">Visible Rows Only</a></li>
<li ng-click="editRows = 'selected'"><a href="#">Selected Rows Only</a></li>
</ul>
</div>
<div class="btn-group" dropdown="true" dropdown-append-to-body="true">
<button class="btn btn-default dropdown-toggle" ng-click="setEditOptions(editField)"
dropdown-toggle="true" type="button">
{{editField | capitalize}} <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li ng-click="editField = 'Program'"><a href="#">Program Enrolled</a></li>
<li ng-click="editField = 'Appl. ASSET'"><a href="#">Applied for ASSET</a></li>
<li ng-click="editField = '4 Year Degree'"><a href="#">4-year degree?</a></li>
</ul>
</div>
<div>
<select ng-model="editValue" ng-options="option.label for option.value in selectOptions">
</select>
</div>
</div>
<button id="split-button" type="button" class="btn btn-default" ng-click="massUpdate()">Modify</button>
</div>
</div>
Am I on the right track? If there is an easier method, or one that would use a button menu directly, please feel free to offer suggestions. Otherwise, is the issue how I am using ng-options?
$scope.$apply()
after setting your select. – Matthew Green