Konfigurationsformular (Select->OnChange->Felder ein-, ausblenden).

Ich sitze hier schon eine Weile am Konfigurationsformular und werde nicht schlauer :frowning:
Nach einer Select Auswahl sollen andere Felder ein/ausgeblendet werden, kann man das umsetzen ?

Im Detail:
Frage-1:
Ich habe ein Select mit 2 Auswahlmöglichkeiten erstellt, OK.
Je nach Auswahl sollten verschiedene „ValidationTextBox“ Felder ein, bzw. ausgeblendet werden.

Frage-2:
Kann der Code/Script beim onChange Event eine Funktion in module.php sein ?

Ich kann im Moment nichts hilfreiches finden was mich hier weiterbringt…
Danke für Hilfe

Schau dir mal das Webinar zu Dynamik an, welche zu IP-Symcon 5.2 gekommen ist. Die UpdateFormField Funktion sollte dein Freund sein in Kombination mit der onChange Methode die du bereits gefunden hast.

paresy

Vielen Dank,

leider klappt das bei mir nicht.

{
    "elements":
    [
        {"type": "Label", "label": "Nmap v1.0, zum Auflisten der Hosts in meinem Netzwerk."},
        {"type": "Label", "label": " Nmap kann entweder auf dem <lokalen Rechner>, oder einem <Remote Host> ausgeführt werden."},
        {"type": "Label", "label": " Bei Ausführung auf einem Remotehost muss vorab die <SSH Public Key Authentifizierung> konfiguriert werden! [ssh-copy-id]"},
        {"type": "Select","name": "Execute","caption": "Ausführen auf",
            "options": 
            [
                { "caption": "Localhost", "value": 0, "onChange": "NMAP_OnChangeLocalhost($id);" },
                { "caption": "Remotehost", "value": 1, "onChange": "NMAP_OnChangeRemotehost($id);" }
            ]
        },
        {"type": "ValidationTextBox","name": "Subnet","caption": "Subnet (CIDR Format: 192.168.1.0/24)"},
        {"type": "ValidationTextBox","name": "NmapPath","caption": "Path (/usr/bin/nmap)"},
        {"type": "ValidationTextBox","name": "SSH_Host","caption": "SSH Remotehost (IP or DNS-Name)"},
        {"type": "ValidationTextBox","name": "SSH_User","caption": "SSH User (root)"}
    ]
}
<?php
    // Klassendefinition
    class Nmap extends IPSModule {
 
        // Überschreibt die interne IPS_Create($id) Funktion
        public function Create() {
            // Diese Zeile nicht löschen.
            parent::Create();

            $this->RegisterPropertyString("Subnet", "192.168.1.0/24");
            $this->RegisterPropertyInteger("Execute", 0);
            $this->RegisterPropertyString("NmapPath", "/usr/bin/nmap");
            $this->RegisterPropertyString("SSH_Host", "192.168.1.10");
            $this->RegisterPropertyString("SSH_User", "root");
 
        }
 
        // Überschreibt die intere IPS_ApplyChanges($id) Funktion
        public function ApplyChanges() {
            // Diese Zeile nicht löschen
            parent::ApplyChanges();

        }
 
        /**
        * Die folgenden Funktionen stehen automatisch zur Verfügung, wenn das Modul über die "Module Control" eingefügt wurden.
        * Die Funktionen werden, mit dem selbst eingerichteten Prefix, in PHP und JSON-RPC wiefolgt zur Verfügung gestellt:
        *
        * ABC_MeineErsteEigeneFunktion($id);
        *
        */
        public function OnChangeLocalhost() {
            echo "!";
            $this->UpdateFormField("Subnet", "enabled", true);
            $this->UpdateFormField("NmapPath", "enabled", true);
            $this->UpdateFormField("SSH_Host", "enabled", false);
            $this->UpdateFormField("SSH_User", "enabled", false);
        }
        public function OnChangeRemotehost() {
            echo "!";
            $this->UpdateFormField("Subnet", "enabled", true);
            $this->UpdateFormField("NmapPath", "enabled", false);
            $this->UpdateFormField("SSH_Host", "enabled", true);
            $this->UpdateFormField("SSH_User", "enabled", true);
        }
    }

Wenn ich den Select in den Actions Teil nehme sind alle anderen Elemente deaktiviert die Funktion in module.php wird jedoch trotzdem nicht ausgeführt, bekomme keine Ausgabe im Log, und es passiert auch sonst nichts…

Guten Rutsch

Das onChange hat nix bei den Options zu suchen, das gehört zum Select Objekt.
Michael

Hallo Michael,

thats it :smiley:

Danke für Hinweis.

(Ich hatte das anfangs auch so drin, jedoch war da noch der Funktionsaufruf inkorrekt…)

Nun habe ich noch das Problem das wenn das Konfigurationsformular neu geöffnet wird jedoch wieder alles sichtbar ist.
Wie kann ich die Funktion beim öffnen des Formulars ausführen ?

        public function OnChangeExecute() {
            if ( $this->ReadPropertyInteger("Execute") == 0 ) {
                $this->UpdateFormField("Subnet", "visible", true);
                $this->UpdateFormField("NmapPath", "visible", true);
                $this->UpdateFormField("SSH_Host", "visible", false);
                $this->UpdateFormField("SSH_User", "visible", false);
            } else {
                $this->UpdateFormField("Subnet", "visible", true);
                $this->UpdateFormField("NmapPath", "visible", false);
                $this->UpdateFormField("SSH_Host", "visible", true);
                $this->UpdateFormField("SSH_User", "visible", true);
            }
        }

Du musst die Form über die Funktion GetConfigurationForm an die Konsole ausliefern. Da kannst du die Form dynamisch anpassen, damit sie beim Laden deinen Wünschen entspricht.
Michael

Vielen Dank.
Ich habe nun den Code der Form direkt in module.php in „public function GetConfigurationForm()“ geschrieben.
Bei Selectauswahl wird hier jedoch immer Execute == 0 durchlaufen, das Formular bekommt also die Änderung nicht mit.

        public function GetConfigurationForm() {
            return '{ "actions": [
                {"type": "Label", "label": "Nmap v1.0, zum Auflisten der Hosts in meinem Netzwerk. [©SimonS]"},
                {"type": "Label", "label": " Nmap kann entweder auf dem <lokalen Rechner>, oder einem <Remote Host> ausgeführt werden."},
                {"type": "Label", "label": " Bei Ausführung auf einem Remotehost muss vorab die <SSH Public Key Authentifizierung> konfiguriert werden! [ssh-copy-id]"},
                {"type": "Select","name": "Execute","caption": "Ausführen auf", "onChange": "NMAP_OnChangeExecute($id);",
                    "options": 
                    [
                        { "caption": "Localhost", "value": 0 },
                        { "caption": "Remotehost", "value": 1 }
                    ]
                },
                {"type": "ValidationTextBox","name": "Subnet","caption": "Subnet (CIDR Format: 192.168.1.0/24)"},
                {"type": "ValidationTextBox","name": "NmapPath","caption": "Path (/usr/bin/nmap)"},
                {"type": "ValidationTextBox","name": "SSH_Host","caption": "SSH Remotehost (IP or DNS-Name)"},
                {"type": "ValidationTextBox","name": "SSH_User","caption": "SSH User (root)"}
            ] }';
        }

        public function OnChangeExecute() {
			//this->ApplyChanges($id);
            if ( $this->ReadPropertyInteger("Execute") == 0 ) {
                echo "Localhost!";
                $this->UpdateFormField("Subnet", "visible", true);
                $this->UpdateFormField("Subnet", "enabled", true);
                $this->UpdateFormField("NmapPath", "visible", true);
                $this->UpdateFormField("NmapPath", "enabled", true);
                $this->UpdateFormField("SSH_Host", "visible", false);
                $this->UpdateFormField("SSH_User", "visible", false);
            } else {
                echo "Remotehost!";
                $this->UpdateFormField("Subnet", "visible", true);
                $this->UpdateFormField("Subnet", "enabled", true);
                $this->UpdateFormField("NmapPath", "visible", false);
                $this->UpdateFormField("SSH_Host", "visible", true);
                $this->UpdateFormField("SSH_Host", "enabled", true);
                $this->UpdateFormField("SSH_User", "visible", true);
                $this->UpdateFormField("SSH_User", "enabled", true);
            }
        }