refactor: add support for ValidatedAccountInput being passed in from outside of the add account forms.

With this change top-level QML code may pass a (populated) ValidatedAccountInput object to pre-populate fields in the add account forms.

Issues: #7, #14
master
Johan Ouwerkerk 2020-09-30 21:48:15 +02:00
parent d33d2c777d
commit 9288f041c8
2 changed files with 33 additions and 1 deletions

View File

@ -17,8 +17,37 @@ Kirigami.FormLayout {
property Models.AccountListModel accounts: Keysmith.accountListModel()
property Models.ValidatedAccountInput validatedInput
onValidatedInputChanged: {
revalidate();
}
property bool acceptable : accountName.acceptableInput && issuerName.acceptableInput
/*
* When accounts are added/removed from the model, the account name and issuer should be revalidated as well.
* It may have become eligible or in-eligible depending on whether or not other accounts with the same name
* for the same new issuer value now (still) exist.
*
* Unfortunately there seems to be nothing to explicitly trigger revalidation on the text field.
* Work around is to force revalidation to happen by "editing" the value in the text field(s) directly.
*/
Connections {
target: accounts
onRowsInserted: {
revalidate();
}
onRowsRemoved: {
revalidate();
}
onModelReset: {
revalidate();
}
}
function revalidate() {
// because of how issuer revalidation works, this also implicitly covers the account name as well
issuerName.insert(issuerName.text.length, "");
}
Controls.TextField {
id: accountName
text: validatedInput.name

View File

@ -26,7 +26,10 @@ Kirigami.Page {
property bool tokenDetailsAcceptable: hotpDetailsAcceptable && totpDetailsAcceptable
property bool acceptable: accountName.acceptable && secretAcceptable && tokenTypeAcceptable && tokenDetailsAcceptable
property Models.ValidatedAccountInput validatedInput: Models.ValidatedAccountInput {
property Models.ValidatedAccountInput validatedInput: Models.ValidatedAccountInput {}
Connections {
target: validatedInput
onTypeChanged: {
root.detailsEnabled = false;
}