qml: validate server address in ServerConfig
Same as Qt, validate the server address the user enters and prevent the user from continuing in the wizard or clicking 'Ok' in the ServerConfig if the entered address is clearly invalid.
This commit is contained in:
@@ -39,6 +39,7 @@ ElDialog {
|
||||
FlatButton {
|
||||
Layout.fillWidth: true
|
||||
text: qsTr('Ok')
|
||||
enabled: serverconfig.addressValid
|
||||
icon.source: '../../icons/confirmed.png'
|
||||
onClicked: {
|
||||
let auto_connect = serverconfig.serverConnectMode == ServerConnectModeComboBox.Mode.Autoconnect
|
||||
|
||||
@@ -12,6 +12,7 @@ Item {
|
||||
property bool showAutoselectServer: true
|
||||
property alias address: address_tf.text
|
||||
property alias serverConnectMode: server_connect_mode_cb.currentValue
|
||||
property alias addressValid: address_tf.valid
|
||||
|
||||
implicitHeight: rootLayout.height
|
||||
|
||||
@@ -28,6 +29,11 @@ Item {
|
||||
|
||||
ServerConnectModeComboBox {
|
||||
id: server_connect_mode_cb
|
||||
onCurrentValueChanged: {
|
||||
if (currentValue == ServerConnectModeComboBox.Mode.Autoconnect) {
|
||||
address_tf.text = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
@@ -63,6 +69,26 @@ Item {
|
||||
enabled: server_connect_mode_cb.currentValue != ServerConnectModeComboBox.Mode.Autoconnect
|
||||
width: parent.width
|
||||
inputMethodHints: Qt.ImhNoPredictiveText
|
||||
|
||||
property bool valid: true
|
||||
|
||||
function validate() {
|
||||
if (!enabled) {
|
||||
valid = true
|
||||
return
|
||||
}
|
||||
valid = Network.isValidServerAddress(address_tf.text)
|
||||
}
|
||||
|
||||
onTextChanged: validate()
|
||||
onEnabledChanged: validate()
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: "red"
|
||||
opacity: 0.2
|
||||
visible: !parent.valid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import QtQuick.Controls
|
||||
import "../controls"
|
||||
|
||||
WizardComponent {
|
||||
valid: true
|
||||
valid: sc.addressValid
|
||||
last: true
|
||||
title: qsTr('Server')
|
||||
|
||||
|
||||
@@ -206,6 +206,10 @@ class QENetwork(QObject, QtEventListener):
|
||||
def server(self):
|
||||
return self._server
|
||||
|
||||
@pyqtSlot(str, result=bool)
|
||||
def isValidServerAddress(self, server: str) -> bool:
|
||||
return ServerAddr.from_str_with_inference(server) is not None
|
||||
|
||||
@pyqtSlot(str, bool, bool)
|
||||
def setServerParameters(self, server_str: str, auto_connect: bool, one_server: bool):
|
||||
net_params = self.network.get_parameters()
|
||||
|
||||
Reference in New Issue
Block a user