[Dropdown] It should be possible to turn off the `onChange` trigger for `set selected` and possibly others
See original GitHub issueI needs OnChange not to be triggered when ‘set selected’ or ‘set value’ is called.
On load I want to prepopulate the dropdown with selections from the server (using ‘set selected’) and only call the OnChange when the user manually selects an item (so it can be added to the server db too).
set selected could have a third parameter “silent”, to prevent triggering onChange which is set to false by default. and I set it to true but nothing happens on change el.dropdown(‘set selected’, value, true);
my directive code is here
(function (module) {
module.directive('searchableDropdown', ["$timeout", searchable]);
function searchable($timeout) {
return {
restrict: 'E',
require: 'ngModel',
replace: true,
scope: {
orderBy: '@',
valueField: '@',
textField: '@',
ngModel: "=",
dropdownItems: '='
},
templateUrl: 'searchableDropdown.html',
link: function (scope, el, atts, ngModel) {
scope.searchableDropdownVm.getSelectedName = function (valueField, textField, selectedValue) {
var itemObj = scope.searchableDropdownVm.dropdownItems.find(function (keyItem) {
return keyItem[valueField] == selectedValue;
});
if (itemObj) {
return itemObj[textField]
}
return '';
};
el.dropdown({
onClick: function (value, text, choice) {
scope.$apply(function () {
ngModel.$setViewValue(value);
});
},
onChange: function (value, text, choice) {
debugger;
scope.$apply(function () {
//ngModel.$setViewValue(value);
//ngModel.ngChange(value);
});
},
forceSelection: false,
selectOnKeydown: false,
showOnFocus: true,
on: "click"
});
ngModel.$render = function () {
$timeout(function () {
//el.dropdown('set text', scope.searchableDropdownVm.getSelectedName(scope.searchableDropdownVm.valueField, scope.searchableDropdownVm.textField, scope.searchableDropdownVm.ngModel));
//el.dropdown('set value', '');
el.dropdown('set selected', ngModel.$viewValue, false);
//el.dropdown('set value', ngModel.$viewValue);
});
};
},
controller: ["$element", "$scope", Controller],
controllerAs: 'searchableDropdownVm',
bindToController: true,
};
function Controller() {
var vm = this;
}
};
})(angular.module('app'));
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
javascript - HTML select element onchange trigger for already ...
When the HTML page is rendered, Flowers is the already selected element in the drop-down by default (being the first one). If I...
Read more >Solved: Problems with ComboBox.OnChange triggering too oft...
Use the OnSelect property to set a context variable to true, if true the OnChange sets the variable to false before proceeding otherwise...
Read more >Documentation: 15: CREATE TRIGGER - PostgreSQL
It is possible for a column's value to change even when the trigger is not fired, because changes made to the row's contents...
Read more >OnChange field Trigger to select another field and set value
Do you have any idea why that would be? ... When I do this, it seems to just set Model = Item, but...
Read more >Misunderstanding Select input and firing an event on change ...
I'm trying to use jquery to change a dropdown value in SharePoint page and when the dropdown value is changed I want to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The community fork Fomantic-UI added support to prevent the change trigger for
set selected
by https://github.com/fomantic/Fomantic-UI/pull/1683@bhosalemahesh899 You could use pre-existing HTML instead of initializing it on a
<select>
element directly:Populate the
.menu
container first, then initialize it withdropdown()
—thenonChange()
will only get triggered with user input.