question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Dropdown] It should be possible to turn off the `onChange` trigger for `set selected` and possibly others

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lubber-decommented, Oct 6, 2022

The community fork Fomantic-UI added support to prevent the change trigger for set selected by https://github.com/fomantic/Fomantic-UI/pull/1683

1reaction
awgvcommented, Mar 30, 2017

@bhosalemahesh899 You could use pre-existing HTML instead of initializing it on a <select> element directly:

<div class="ui selection dropdown">
  <input type="hidden" name="name">
  <i class="dropdown icon"></i>
  <div class="default text">Default text</div>
  <div class="menu">
    <div class="item" data-value="value">Text</div>
  </div>
</div>

Populate the .menu container first, then initialize it with dropdown()—then onChange() will only get triggered with user input.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found