fix of regex

pull/1/head
Rob Stupay 7 years ago
parent d9246688db
commit 6e11efe348
  1. 46
      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 (ret !== '') ret += ',' if (elA) notEmpty++
ret += el.value }
if (notEmpty) {
for (var j = 0; j < valArray.length; j++) {
if (ret !== '') ret += ','
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,11 +67,14 @@ class MultiParamManager {
makeMultiVal () { makeMultiVal () {
var inputString = this.basicInputField.value var inputString = this.basicInputField.value
var inputJSON = JSON.parse('[' + inputString + ']') if (inputString) {
var multiInputs = this.multiFields.querySelectorAll('input') inputString = inputString.replace(/(^|,\s+|,)(\w+|)(\s+,|,|$)/g, '$1"$2"$3')
for (var k = 0; k < multiInputs.length; k++) { var inputJSON = JSON.parse('[' + inputString + ']')
if (inputJSON[k]) { var multiInputs = this.multiFields.querySelectorAll('input')
multiInputs[k].value = JSON.stringify(inputJSON[k]) for (var k = 0; k < multiInputs.length; k++) {
if (inputJSON[k]) {
multiInputs[k].value = JSON.stringify(inputJSON[k])
}
} }
} }
} }
@ -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