mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2026-02-01 04:10:00 +01:00
Fix [required] fields not working in Microsoft Edge with Selectize.js (#1222)
This commit is contained in:
committed by
Andy Miller
parent
e54fcbecbb
commit
bca7f7bbf4
@@ -96,6 +96,7 @@ export default class FilePickerField {
|
||||
};
|
||||
|
||||
field.selectize({
|
||||
plugins: ['required-fix'],
|
||||
valueField: 'name',
|
||||
labelField: 'name',
|
||||
searchField: 'name',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import $ from 'jquery';
|
||||
import 'selectize';
|
||||
import '../../utils/selectize-required-fix';
|
||||
|
||||
export default class SelectizeField {
|
||||
constructor(options = {}) {
|
||||
@@ -19,7 +20,9 @@ export default class SelectizeField {
|
||||
let field = (isInput ? element : element.find('input, select'));
|
||||
|
||||
if (!field.length || field.get(0).selectize) { return; }
|
||||
field.selectize(data);
|
||||
field.selectize($.extend({}, data, {
|
||||
plugins: ['required-fix']
|
||||
}));
|
||||
|
||||
this.elements.push(field.data('selectize'));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import request from '../utils/request';
|
||||
import debounce from 'debounce';
|
||||
import { Instance as pagesTree } from './tree';
|
||||
import 'selectize';
|
||||
import '../utils/selectize-required-fix.js';
|
||||
import '../utils/storage';
|
||||
|
||||
/* @formatter:off */
|
||||
@@ -138,7 +139,7 @@ export default class PagesFilter {
|
||||
optgroupLabelField: 'name',
|
||||
optgroupValueField: 'id',
|
||||
optgroupOrder: this.labels.map((item) => item.id),
|
||||
plugins: ['optgroup_columns']
|
||||
plugins: ['optgroup_columns', 'required-fix']
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
28
themes/grav/app/utils/selectize-required-fix.js
Normal file
28
themes/grav/app/utils/selectize-required-fix.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* This is a plugin to override the `.refreshValidityState` method of
|
||||
* the Selectize library (https://selectize.github.io/selectize.js/).
|
||||
* The library is not maintained anymore (as of 2017-09-13) and contains
|
||||
* a bug which causes Microsoft Edge to not work with selectized [required]
|
||||
* form fields. This plugin should be removed if
|
||||
* https://github.com/selectize/selectize.js/pull/1320 is ever merged
|
||||
* and a new version of Selectize gets released.
|
||||
*/
|
||||
|
||||
import Selectize from 'selectize';
|
||||
|
||||
Selectize.define('required-fix', function(options) {
|
||||
this.refreshValidityState = () => {
|
||||
if (!this.isRequired) return false;
|
||||
|
||||
let invalid = !this.items.length;
|
||||
this.isInvalid = invalid;
|
||||
|
||||
if (invalid) {
|
||||
this.$control_input.attr('required', '');
|
||||
this.$input.removeAttr('required');
|
||||
} else {
|
||||
this.$control_input.removeAttr('required');
|
||||
this.$input.attr('required');
|
||||
}
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user