I use ng-pattern
to have validation on one of text inputs. Is there a way to trigger the validation only if the text input has been modified? Or in other words, the validation should not be triggered when text input is pristine, ie. not modified by the user (perhaps by setPristine(true)
. Not sure, but this could be done by setting the field as valid on init. Here's a part of my code (from *.jade file):
+text_input('Flat number', 'flatNumber', '', null, {
tooltip: '{{ "invalid_flat_number_tooltip" | translate }}'
})(ng-disabled='!editable', ng-readonly='!editable', ng-pattern="/^(?:\\d{1,3}[A-Z]?(?:\\/\\d{1,3})?)?$/", label-s)
ng-pattern supports dynamic value, so eg you can have this:
ng-pattern="$ctrl.pattern" ng-change="$ctrl.setPattern()"
const realPattern = /.../;
vm.pattern = ''
vm.setPattern = () => vm.pattern = realPattern;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.