Skip to content

Commit

Permalink
Fixed issue where not working on iOS due to regex
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOmnimax committed Mar 27, 2020
1 parent 516d925 commit cfe95cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
Binary file modified extrabuttons.fieldplugin.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion source/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "Extra buttons",
"author" : "Dobility",
"version": "1.1.0",
"version": "1.1.1",
"supportedFieldTypes": ["text", "integer", "decimal"],
"hideDefaultRequiredMessage": true,
"hideDefaultConstraintMessage": true
Expand Down
32 changes: 19 additions & 13 deletions source/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,31 +202,37 @@ function cursorToEnd(el) { //Moves cursor to end of text in text box (incondiste
input.oninput = function () {
formGroup.classList.remove('has-error');
controlMessage.innerHTML = "";
let answer = input.value.toString();
let currentAnswer = input.value;

if(appearance.includes('show_formatted')){
let pointLoc = answer.indexOf('.');
if (appearance.includes('show_formatted')) {
let ansString = currentAnswer.toString();
let pointLoc = currentAnswer.indexOf('.');

if(pointLoc == -1){
formattedSpan.innerHTML = answer.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
if (pointLoc == -1) {
formattedSpan.innerHTML = ansString.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
else{
let beforePoint = answer.substring(0, pointLoc).replace(/\B(?=(\d{3})+(?!\d))/g, ","); //Before the decimal point
let midPoint = answer.substring(pointLoc + 1, pointLoc + 3); //The first two digits after the decimal point; this is because the first two digits after the decimal point are the "tenths" and "hundredths", while after that is "thousandths"
else {
let beforePoint = ansString.substring(0, pointLoc).replace(/\B(?=(\d{3})+(?!\d))/g, ","); //Before the decimal point

//The part below adds commas to the numbers after the decimal point. Unfortunately, a lookbehind assersion breaks the JS in iOS right now, so this has been commented out for now.
/*let midPoint = answer.substring(pointLoc + 1, pointLoc + 3); //The first two digits after the decimal point; this is because the first two digits after the decimal point are the "tenths" and "hundredths", while after that is "thousandths"
let afterPoint = answer.substring(pointLoc + 3, answer.length).replace(/\B(?<=(^(\d{3})+))/g, ","); //After the first two digits after the decimal point
let total = beforePoint;

if(midPoint != ''){ //Adds the decimal point only if it is needed
if (midPoint != '') { //Adds the decimal point only if it is needed
total += '.' + midPoint;
if(afterPoint != ''){ //Adds the comma after "midPoint" and the rest only if they are needed
if (afterPoint != '') { //Adds the comma after "midPoint" and the rest only if they are needed
total += ',' + afterPoint;
}
}
}*/
let afterPoint = ansString.substring(pointLoc, ansString.length);
let total = beforePoint + afterPoint;

formattedSpan.innerHTML = total;
}
}

setAnswer(answer);
setAnswer(currentAnswer);
}


Expand Down

0 comments on commit cfe95cf

Please sign in to comment.