From f83ad4c2767b6526fe0abea4c8ed7d44b3093fb6 Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Thu, 26 Apr 2018 15:10:02 +0200 Subject: [PATCH] updating some of issues 1250 --- src/multiParamManager.js | 56 +++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/src/multiParamManager.js b/src/multiParamManager.js index 08cb124cb9..5e9e7cab4f 100644 --- a/src/multiParamManager.js +++ b/src/multiParamManager.js @@ -20,16 +20,51 @@ class MultiParamManager { this.clickCallBack = clickCallBack this.inputs = inputs this.title = title + this.basicInputField + this.multiFields } 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() + } + getMultiValsString () { + var valArray = this.multiFields.querySelectorAll('input') + var ret = '' + for (var k = 0; k < valArray.length; k++) { + var el = valArray[k] + if (ret !== '') ret += ',' + ret += el.value + } + return ret + } + + emptyInputs () { + var valArray = this.multiFields.querySelectorAll('input') + for (var k = 0; k < valArray.length; k++) { + valArray[k].value = '' + } + this.basicInputField.value = '' + } + + makeMultiVal () { + var inputString = this.basicInputField.value + console.log(inputString) + var inputStringArray = inputString.split(',') + // !! the split here will mess up a value with a comma in it !! + // do we not make a split if its a , inside a []? + var multiInputs = this.multiFields.querySelectorAll('input') + for (var k = 0; k < multiInputs.length; k++) { + multiInputs[k].value = inputStringArray[k] + } } createMultiFields () { @@ -52,28 +87,31 @@ class MultiParamManager { title = '(fallback)' } - var basicInputField = yo`` - basicInputField.setAttribute('placeholder', this.inputs) - basicInputField.setAttribute('title', this.inputs) + this.basicInputField = yo`` + this.basicInputField.setAttribute('placeholder', this.inputs) + this.basicInputField.setAttribute('title', this.inputs) var onClick = (domEl) => { - this.clickCallBack(this.funABI.inputs, basicInputField.value) + this.clickCallBack(this.funABI.inputs, this.basicInputField.value) + this.emptyInputs() } this.contractActionsContainerSingle = yo`
- ${basicInputField} { this.switchMethodViewOn() }} title=${title} > + ${this.basicInputField} { this.switchMethodViewOn() }} title=${title} >
` - var multiFields = this.createMultiFields() + this.multiFields = this.createMultiFields() var multiOnClick = () => { - var valArray = multiFields.querySelectorAll('input') + var valArray = this.multiFields.querySelectorAll('input') var ret = '' for (var k = 0; k < valArray.length; k++) { var el = valArray[k] if (ret !== '') ret += ',' + el.value = el.value.replace(/(^|,\s+|,)([a-zA-Z]+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted string - that starts with a letter ret += el.value } this.clickCallBack(this.funABI.inputs, ret) + this.emptyInputs() } var button = yo`` @@ -84,7 +122,7 @@ class MultiParamManager {
${title}
- ${multiFields} + ${this.multiFields}
${button}
@@ -106,7 +144,7 @@ class MultiParamManager { contractProperty.classList.add(css.hasArgs) } else { this.contractActionsContainerSingle.querySelector('i').style.visibility = 'hidden' - basicInputField.style.display = 'none' + this.basicInputField.style.display = 'none' } if (this.funABI.payable === true) {