selectize-required-fix.js 978 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * This is a plugin to override the `.refreshValidityState` method of
  3. * the Selectize library (https://selectize.github.io/selectize.js/).
  4. * The library is not maintained anymore (as of 2017-09-13) and contains
  5. * a bug which causes Microsoft Edge to not work with selectized [required]
  6. * form fields. This plugin should be removed if
  7. * https://github.com/selectize/selectize.js/pull/1320 is ever merged
  8. * and a new version of Selectize gets released.
  9. */
  10. import Selectize from 'selectize';
  11. Selectize.define('required-fix', function(options) {
  12. this.refreshValidityState = () => {
  13. if (!this.isRequired) return false;
  14. let invalid = !this.items.length;
  15. this.isInvalid = invalid;
  16. if (invalid) {
  17. this.$control_input.attr('required', '');
  18. this.$input.removeAttr('required');
  19. } else {
  20. this.$control_input.removeAttr('required');
  21. this.$input.attr('required');
  22. }
  23. };
  24. });