Commit dd77100e authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Improved band gap search validation and behaviour.

parent f833923f
Pipeline #85027 skipped with stage
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -258,6 +258,30 @@ class PropertiesBox {
*/
// this.checkbox.checked
this._events();
// Set up input validation for band gap min and max
function setInputFilter(textbox, inputFilter) {
["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach(function(event) {
textbox.addEventListener(event, function() {
if (inputFilter(this.value)) {
this.oldValue = this.value;
this.oldSelectionStart = this.selectionStart;
this.oldSelectionEnd = this.selectionEnd;
} else if (this.hasOwnProperty("oldValue")) {
this.value = this.oldValue;
this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
} else {
this.value = "";
}
});
});
}
setInputFilter(this.element.getElementsByClassName("band-gap-min-field")[0], function(value) {
return /^\d*\.?\d*$/.test(value); // Allow digits and '.' only, using a RegExp
});
setInputFilter(this.element.getElementsByClassName("band-gap-max-field")[0], function(value) {
return /^\d*\.?\d*$/.test(value); // Allow digits and '.' only, using a RegExp
});
}
......@@ -361,23 +385,23 @@ class PropertiesBox {
let maxField = document.querySelector('.band-gap-max-field');
let fieldName = 'band-gap';
let label = 'Band Gap';
if (minField.value !== ''){
let empty = true;
if (minField.value !== '') {
empty = false;
label = minField.value+' < '+label;
fieldName += ':'+minField.value;
if (reset) minField.value = '';
} else {
fieldName += ':';
}
if (maxField.value !== ''){
if (maxField.value !== '') {
empty = false;
label += ' < '+maxField.value;
fieldName += ':'+maxField.value;
if (reset) maxField.value = '';
} else {
fieldName += ':';
}
propsMap.set(fieldName, [label]);
if (!empty) {
propsMap.set(fieldName, [label]);
}
//if (label !== 'Band Gap'){
//let val = document.querySelector('input[name="band-gap-type"]:checked').value;
//if (val === 'd') fieldName += ':True';
......
......@@ -183,11 +183,22 @@ class SearchMod {
elements.push(item);
} else if (this.queryTypes[i] !== 'S') { // property
if (this.queryTypes[i].indexOf('band-gap') === 0) { // special case
let bandGapData = this.queryTypes[i].split(':');
queryObj.band_gap = {
"min": parseFloat(bandGapData[1]),
"max": parseFloat(bandGapData[2])
};
let bandGapData = item.split('<');
let bandGapQuery = {};
if (bandGapData.length == 3) {
bandGapQuery.min = parseFloat(bandGapData[0]);
bandGapQuery.max = parseFloat(bandGapData[2]);
} else {
if (item.startsWith("Band Gap")) {
bandGapQuery.min = null;
bandGapQuery.max = parseFloat(bandGapData[1]);
} else {
bandGapQuery.min = parseFloat(bandGapData[0]);
bandGapQuery.max = null;
}
}
queryObj.band_gap = bandGapQuery;
console.log(queryObj.band_gap);
//queryObj.band_gap_direct = bandGapData[3];
//}else if (this.queryTypes[i].indexOf('mass-density') === 0){ // special case
//let massDensity = this.queryTypes[i].split(':');
......@@ -331,7 +342,15 @@ class SearchMod {
let i = this.queryTypes.indexOf(propName);
if (i < 0)
this.addTagInSearchQuery(values.join(' | '), propName);
else{
else {
// If a new band gap range is given it overrides the old one.
if (propName === "band-gap") {
this.searchQuery[i] = values[0];
this.updateSearchQuery();
this._showSearchBox();
return;
}
let currentValues = this.searchQuery[i].split(' | ');
//console.log('Current VAlues: ',currentValues);
values.forEach(value => {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment