mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fix
This commit is contained in:
+27
-25
@@ -349,7 +349,17 @@ kit.PluginManager.register('toolkit',function(module, exports, require) {
|
||||
function changeHandler(e) {
|
||||
var select = e.target;
|
||||
changeSelect(select);
|
||||
console.log('changeHandler');
|
||||
}
|
||||
|
||||
|
||||
function __dirtyTests(value, dirtyValidTestData) {
|
||||
var r = true;
|
||||
dirtyValidTestData.forEach(function(attr, i){
|
||||
if(attr.name === 'data-dirty-min') {
|
||||
r = r && (Number(value) >= Number(attr.value))
|
||||
}
|
||||
});
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -357,7 +367,7 @@ kit.PluginManager.register('toolkit',function(module, exports, require) {
|
||||
* @param select {HTMLElement}
|
||||
*/
|
||||
function changeSelect(select) {
|
||||
if (hasClass(select, 'kit-field__input') && select.tagName == 'SELECT') {
|
||||
if (hasClass(select, 'kit-field__input') && select.tagName === 'SELECT') {
|
||||
var selected = select.querySelectorAll('option:checked')[0];
|
||||
var data = {};
|
||||
var dataAttrs = [];
|
||||
@@ -368,32 +378,35 @@ kit.PluginManager.register('toolkit',function(module, exports, require) {
|
||||
});
|
||||
}
|
||||
|
||||
var dirtyValidTestData = [];
|
||||
dirtyValidTestData = dirtyValidTestData.filter.call(select.attributes, function (attr) {
|
||||
return (/^data-dirty-/.test(attr.name)
|
||||
);
|
||||
});
|
||||
|
||||
var isMultiple = select.hasAttribute('multiple');
|
||||
|
||||
var parent = select.parentNode;
|
||||
|
||||
var display = select.parentNode.querySelector('.kit-field__display');
|
||||
|
||||
var bDisplay = true;
|
||||
|
||||
//if(parent && parent.classList.contains('kit-field--select-link') && isMultiple) {
|
||||
var bDirty = !!selected;
|
||||
if(isMultiple) {
|
||||
bDisplay = false;
|
||||
bDirty = false;
|
||||
}
|
||||
if(!isMultiple) {
|
||||
bDirty = bDirty && __dirtyTests(select.value, dirtyValidTestData);
|
||||
}
|
||||
|
||||
display.textContent = '';
|
||||
|
||||
if(bDisplay && selected) {
|
||||
if(bDirty) {
|
||||
display.textContent = selected.textContent;
|
||||
}
|
||||
|
||||
removeClass(parent, 'kit-select--open');
|
||||
|
||||
if(selected) {
|
||||
select.setAttribute('data-dirty', 'true');
|
||||
} else {
|
||||
select.setAttribute('data-dirty', 'false');
|
||||
}
|
||||
select.setAttribute('data-dirty', bDirty?'true':'false');
|
||||
|
||||
removeClass(select, 'kit-field--error');
|
||||
|
||||
@@ -468,28 +481,18 @@ kit.PluginManager.register('toolkit',function(module, exports, require) {
|
||||
var textContent = item.textContent;
|
||||
var dropdownInnerIcon = document.createElement('span');
|
||||
var dropdownInnerIconCheck = '<svg viewBox="0 0 24 24"><path d="M9.001,16.212l-4.199-4.2l-1.4,1.4l5.6,5.6l12-12l-1.4-1.4L9.001,16.212z"></path></svg>';
|
||||
var dataClass = String(item.getAttribute('data-class'));
|
||||
addClass(dropdownInnerIcon, 'kit-field__icon');
|
||||
$(dropdownInnerIcon).append(dropdownInnerIconCheck);
|
||||
dropdownInner.textContent = textContent;
|
||||
dropdownInner.setAttribute('data-index', i);
|
||||
|
||||
addClass(dropdownInner, 'kit-dropdown__option');
|
||||
addClass(dropdownInner, dataClass);
|
||||
|
||||
if (isMultiple) {
|
||||
dropdownInner.appendChild(dropdownInnerIcon);
|
||||
}
|
||||
// if (item.getAttribute( "block_selected_off" ) == "active") {
|
||||
// addClass(dropdownInner, 'block_selected_off');
|
||||
// dropdownInner.appendChild(dropdownInnerIcon);
|
||||
// }
|
||||
// if (item.getAttribute( "block_selected" ) == "active") {
|
||||
// addClass(dropdownInner, 'block_selected');
|
||||
// dropdownInner.appendChild(dropdownInnerIcon);
|
||||
// }
|
||||
// if (item.getAttribute( "block_selected" ) == "noActive") {
|
||||
// addClass(dropdownInner, 'block_selected_no');
|
||||
// dropdownInner.appendChild(dropdownInnerIcon);
|
||||
// }
|
||||
if (item.disabled) {
|
||||
addClass(dropdownInner, 'kit-disabled');
|
||||
}
|
||||
@@ -731,7 +734,6 @@ kit.PluginManager.register('toolkit',function(module, exports, require) {
|
||||
return _this.changeFiled(e);
|
||||
}, false);
|
||||
document.addEventListener('change', function (e) {
|
||||
console.log('change');
|
||||
return _this.switchField(e);
|
||||
}, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user