fix(RecipientSelector): Fixed validation
This commit is contained in:
parent
44cf440a05
commit
3b40649b7b
|
@ -25,7 +25,7 @@ StatusDialog {
|
||||||
signal save(string name, string address)
|
signal save(string name, string address)
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
id: _internal
|
id: d
|
||||||
property int validationMode: root.edit ?
|
property int validationMode: root.edit ?
|
||||||
StatusInput.ValidationMode.Always
|
StatusInput.ValidationMode.Always
|
||||||
: StatusInput.ValidationMode.OnlyWhenDirty
|
: StatusInput.ValidationMode.OnlyWhenDirty
|
||||||
|
@ -74,7 +74,7 @@ StatusDialog {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
charLimit: 40
|
charLimit: 40
|
||||||
validationMode: _internal.validationMode
|
validationMode: d.validationMode
|
||||||
}
|
}
|
||||||
|
|
||||||
// To-Do use StatusInput within the below component
|
// To-Do use StatusInput within the below component
|
||||||
|
@ -105,7 +105,7 @@ StatusDialog {
|
||||||
rightButtons: ObjectModel {
|
rightButtons: ObjectModel {
|
||||||
StatusButton {
|
StatusButton {
|
||||||
text: root.edit ? qsTr("Save") : qsTr("Add address")
|
text: root.edit ? qsTr("Save") : qsTr("Add address")
|
||||||
enabled: _internal.valid && _internal.dirty
|
enabled: d.valid && d.dirty
|
||||||
onClicked: root.save(name, address)
|
onClicked: root.save(name, address)
|
||||||
objectName: "addSavedAddress"
|
objectName: "addSavedAddress"
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,7 @@ Item {
|
||||||
property bool isSelectorVisible: true
|
property bool isSelectorVisible: true
|
||||||
property bool addContactEnabled: true
|
property bool addContactEnabled: true
|
||||||
property bool isPending: {
|
property bool isPending: {
|
||||||
if (!selAddressSource.currentValue) {
|
switch (selAddressSource.currentValue) {
|
||||||
return false
|
|
||||||
}
|
|
||||||
switch (selAddressSource.currentValue.value) {
|
|
||||||
case RecipientSelector.Type.Address:
|
case RecipientSelector.Type.Address:
|
||||||
return inpAddress.isPending
|
return inpAddress.isPending
|
||||||
case RecipientSelector.Type.Contact:
|
case RecipientSelector.Type.Contact:
|
||||||
|
@ -60,23 +57,18 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate() {
|
function validate() {
|
||||||
let isValid = true
|
switch (selAddressSource.currentValue) {
|
||||||
if (!selAddressSource.currentValue) {
|
|
||||||
return root.isValid
|
|
||||||
}
|
|
||||||
switch (selAddressSource.currentValue.value) {
|
|
||||||
case RecipientSelector.Type.Address:
|
case RecipientSelector.Type.Address:
|
||||||
isValid = inpAddress.isValid
|
root.isValid = inpAddress.isValid
|
||||||
break
|
break
|
||||||
case RecipientSelector.Type.Contact:
|
case RecipientSelector.Type.Contact:
|
||||||
isValid = selContact.isValid
|
root.isValid = selContact.isValid
|
||||||
break
|
break
|
||||||
case RecipientSelector.Type.Account:
|
case RecipientSelector.Type.Account:
|
||||||
isValid = selAccount.isValid
|
root.isValid = selAccount.isValid
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
root.isValid = isValid
|
return root.isValid
|
||||||
return isValid
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateAddressComboBox() {
|
function updateAddressComboBox() {
|
||||||
|
@ -169,10 +161,8 @@ Item {
|
||||||
parentWidth: parent.width
|
parentWidth: parent.width
|
||||||
addContactEnabled: root.addContactEnabled
|
addContactEnabled: root.addContactEnabled
|
||||||
onSelectedAddressChanged: {
|
onSelectedAddressChanged: {
|
||||||
if (!selAddressSource.currentValue || (selAddressSource.currentValue && selAddressSource.currentValue.value !== RecipientSelector.Type.Address)) {
|
if (selAddressSource.currentValue !== RecipientSelector.Type.Address)
|
||||||
return
|
return
|
||||||
}
|
|
||||||
|
|
||||||
root.selectedRecipient = { address: selectedAddress, type: RecipientSelector.Type.Address }
|
root.selectedRecipient = { address: selectedAddress, type: RecipientSelector.Type.Address }
|
||||||
}
|
}
|
||||||
onIsValidChanged: root.validate()
|
onIsValidChanged: root.validate()
|
||||||
|
@ -189,9 +179,8 @@ Item {
|
||||||
Layout.alignment: Qt.AlignTop
|
Layout.alignment: Qt.AlignTop
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
onSelectedContactChanged: {
|
onSelectedContactChanged: {
|
||||||
if (!selectedContact || !selAddressSource.currentValue || !selectedContact.address || (selAddressSource.currentValue && selAddressSource.currentValue.value !== RecipientSelector.Type.Contact)) {
|
if (!selectedContact || !selectedContact.address || selAddressSource.currentValue !== RecipientSelector.Type.Contact)
|
||||||
return
|
return;
|
||||||
}
|
|
||||||
const { address, name, alias, pubKey, icon, isContact, ensVerified } = selectedContact
|
const { address, name, alias, pubKey, icon, isContact, ensVerified } = selectedContact
|
||||||
root.selectedRecipient = { address, name, alias, pubKey, icon, isContact, ensVerified, type: RecipientSelector.Type.Contact }
|
root.selectedRecipient = { address, name, alias, pubKey, icon, isContact, ensVerified, type: RecipientSelector.Type.Contact }
|
||||||
}
|
}
|
||||||
|
@ -209,14 +198,14 @@ Item {
|
||||||
Layout.alignment: Qt.AlignTop
|
Layout.alignment: Qt.AlignTop
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
onSelectedAccountChanged: {
|
onSelectedAccountChanged: {
|
||||||
if (!selectedAccount || !selAddressSource.currentValue || (selAddressSource.currentValue && selAddressSource.currentValue.value !== RecipientSelector.Type.Account)) {
|
if (!selectedAccount || selAddressSource.currentValue !== RecipientSelector.Type.Account)
|
||||||
return
|
return;
|
||||||
}
|
|
||||||
const { address, name, color, assets, fiatBalance } = selectedAccount
|
const { address, name, color, assets, fiatBalance } = selectedAccount
|
||||||
root.selectedRecipient = { address, name, color, assets, fiatBalance, type: RecipientSelector.Type.Account }
|
root.selectedRecipient = { address, name, color, assets, fiatBalance, type: RecipientSelector.Type.Account }
|
||||||
}
|
}
|
||||||
onIsValidChanged: root.validate()
|
onIsValidChanged: root.validate()
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusComboBox {
|
StatusComboBox {
|
||||||
id: selAddressSource
|
id: selAddressSource
|
||||||
visible: isSelectorVisible && !root.readOnly
|
visible: isSelectorVisible && !root.readOnly
|
||||||
|
@ -229,7 +218,7 @@ Item {
|
||||||
control.valueRole: "value"
|
control.valueRole: "value"
|
||||||
|
|
||||||
onCurrentValueChanged: {
|
onCurrentValueChanged: {
|
||||||
if (root.readOnly || !currentValue) {
|
if (root.readOnly) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let address, name
|
let address, name
|
||||||
|
|
Loading…
Reference in New Issue