Is there a way to cancel ng-change
event?
Actually I want to have an option in a select box but do not want user to select it but want to give a warning message and then make the previous option selected.
For that I think the best way should be if I can cancel the ng-change
event in some way so it does not make any effect, something similar like when we return false in html onchange
event it does not let you change the option.
I also tried to store the previous value in someway and then set that value in ng-change
event but then found that ng-change
doesn't pass event
variable and so I cannot find the element triggering the event.
Any idea?
Edit
Something like this
<select ng-change="DeliveryMethodChange(item)" ng-model="item.DeliveryMethodId" ng-options="method.Key as method.Value for method in deliveryMethods">
<option value="">(Please Select)</option>
</select>
Script
$scope.DeliveryMethodChange = function(item) {
if (item.DeliveryMethodId.toUpperCase() == 'SH') {
// here I want to reset the value to the previously selected value
alert('You cannot select this delivery method');
return false;
}
// rest of the code
};