materialize icon indicating copy to clipboard operation
materialize copied to clipboard

Click event triggered for the option even when it is already selected in material select

Open VicJohn opened this issue 9 years ago • 3 comments

Expected Behavior

When selecting an option which is in selected state, should not trigger onchange event again and again

Current Behavior

When selecting an option which is in selected state, triggering onchange event whenever selected

Steps to Reproduce (for bugs)

  1. Navigate to http://materializecss.com/forms.html#select
  2. Register the following onchange event in browser console by opening developer tools
  3. $(document).on('change','#select',function(){alert('1');});
  4. Now select an option from material select which was converted by calling material_select() method. Not browser default. Alert will show 1.
  5. Now again select the option which is already selected. Again onchange event triggered and alert shown.

Your Environment

  • Version used: v0.98.1
  • Browser Name and version: Firefox 56.0 64 bit
  • Operating System and version (desktop or mobile): Desktop

VicJohn avatar Oct 24 '17 04:10 VicJohn

I think that is not an undesirable bug. One way to fix the problem would be to have a global variable which is going to store current value from the select. Whenever onchange is triggered, you can do a check if the value is same as the old value. If true then do something else.

samlovescoding avatar Oct 25 '17 11:10 samlovescoding

That is OK. I Agree. This can be accepted when the number of dropdowns are limited. What if I have n number of pages and n number of dropdowns in each page?

VicJohn avatar Oct 25 '17 12:10 VicJohn

Alternatively we should not react on the selected list item. I will see if this issue is reproducible in v1 Branch. If yes will fix it

developeranirudhprabhu avatar Nov 16 '17 18:11 developeranirudhprabhu