fix of regex

pull/1/head
Rob Stupay 7 years ago
parent d9246688db
commit 6e11efe348
  1. 34
      src/multiParamManager.js

@ -28,22 +28,31 @@ class MultiParamManager {
switchMethodViewOn () {
this.contractActionsContainerSingle.style.display = 'none'
this.contractActionsContainerMulti.style.display = 'flex'
// fill in the inputs
this.makeMultiVal()
}
switchMethodViewOff () {
this.contractActionsContainerSingle.style.display = 'flex'
this.contractActionsContainerMulti.style.display = 'none'
this.basicInputField.value = this.getMultiValsString()
if (this.getMultiValsString()) this.basicInputField.value = this.getMultiValsString()
}
getMultiValsString () {
var valArray = this.multiFields.querySelectorAll('input')
var notEmpty = 0
var ret = ''
for (var k = 0; k < valArray.length; k++) {
var el = valArray[k]
var elA = valArray[k].value
if (elA) notEmpty++
}
if (notEmpty) {
for (var j = 0; j < valArray.length; j++) {
if (ret !== '') ret += ','
ret += el.value
var elVal = valArray[j].value
elVal = elVal.replace(/(^|,\s+|,)(\w+|)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted string or number by quoted string
ret += elVal
}
}
return ret
}
@ -58,6 +67,8 @@ class MultiParamManager {
makeMultiVal () {
var inputString = this.basicInputField.value
if (inputString) {
inputString = inputString.replace(/(^|,\s+|,)(\w+|)(\s+,|,|$)/g, '$1"$2"$3')
var inputJSON = JSON.parse('[' + inputString + ']')
var multiInputs = this.multiFields.querySelectorAll('input')
for (var k = 0; k < multiInputs.length; k++) {
@ -66,6 +77,7 @@ class MultiParamManager {
}
}
}
}
createMultiFields () {
if (this.funABI.inputs) {
@ -101,16 +113,14 @@ class MultiParamManager {
</div>`
this.multiFields = this.createMultiFields()
var multiOnClick = () => {
var valArray = this.multiFields.querySelectorAll('input')
var ret = ''
for (var k = 0; k < valArray.length; k++) {
let el = valArray[k].value
if (ret !== '') ret += ','
el = el.replace(/(^|,\s+|,)(\w+|)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted string or number by quoted string
ret += el
var valsString = this.getMultiValsString()
if (valsString) {
this.clickCallBack(this.funABI.inputs, valsString)
} else {
this.clickCallBack(this.funABI.inputs, '')
}
this.clickCallBack(this.funABI.inputs, ret)
this.emptyInputs()
}

Loading…
Cancel
Save