I'm using a switch function with a unit converter that allows a user to swap units instead of changing their selection. It works fine then I noticed that in some cases it failed.
I went through all the options until reducing the size of the value field/ It then worked. I assumed that the value was too long but after checking on here:
Max length of an HTML attribute value
it looks like I was well within the boundaries. So I'm wondering what else it could be?
Below are two examples taken from the console log showing Before and After the switch button was pressed and the results once I changed the name.
Measurement Type: thermalExpansion
convertFunctions.js:30BEFORE!!! from: length/length/degreeC to: length/length/degreeRan
convertFunctions.js:40AFTER!!! from: length/length/degreeC to: length/length/degreeRan
convertFunctions.js:1020Parsed input is 1 and result is 0.555555556
Measurement Type: thermalExpansion
convertFunctions.js:30BEFORE!!! from: lengthRan to: lengthk
convertFunctions.js:40AFTER!!! from: lengthk to: lengthRan
EDIT: I just tested again using the oblique in the field and it failed.
EDIT AGAIN: More Info:
The function, shows where the console logs were generated
function switchUnits(){
//need to get values before swap to and from around.
var from = $("#from").val();
var to = $("#to").val();
console.log('BEFORE!!! from: ', from, 'to: ', to );
//switches the details
$("#to #"+from).attr("selected","selected");
$("#from #"+to).attr("selected","selected");
//gets values after switch
from = $("#from").val();
to = $("#to").val();
console.log('AFTER!!! from: ', from, 'to: ', to );
//run convert
convertUnits();
}
Example of the JSON file once edited to remove all '/' from the value field
Before edit example:
"thermalExpansion":[
{
"value": "length/degreek",
"name" : "Length / Length / Kelvin (1/K)"
},
],
After edit example:
"thermalExpansion":[
{
"value": "lengthk",
"name" : "Length / Length / Kelvin (1/K)"
}
],