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

Loading…
Cancel
Save