data_type = 'set'; $this->item_hide_icon = true; } /** * Overwrite method show_item: create listbox from set */ protected function show_item() { if ( $this->is_key_column && ! $this->show_context_update_keys_allowed ) { // PROBLEM // Key columns are set to readonly. This will not work for listboxes. // Therefor listboxes need to be set to disabled. Disabled values however // are not available in a post ($_POST/$_REQUEST). // SOLUTION // Disable listbox (see JS when document is loaded) and add a hidden field // holding the key value (HERE). ?> is_nullable && ( '' === $this->item_value || null === $this->item_value ) ) { return true; } if ( 'set' === substr( $this->column_type, 0, 3 ) ) { // Get set from MySQL table. $allowed_values = explode( ',', str_replace( '\'', '', substr( substr( (string) $this->column_type, 4 ), 0, - 1 ) ) ); // phpcs:ignore -- 8.1 proof $entered_values = explode( ',', ( string ) $this->item_value ); // phpcs:ignore -- 8.1 proof // Check if all values are in set foreach ( $entered_values as $entered_value ) { $value_found = false; foreach ( $allowed_values as $allowed_value ) { if ( $allowed_value === $entered_value ) { $value_found = true; // Value allowed. } } if ( ! $value_found ) { // Value not in enum: inform user and set validation to failed. $msg = new WPDA_Message_Box( array( 'message_text' => 'Value for ' . str_replace( '_', ' ', $this->item_name ) . ' ' . __( 'not allowed', 'wp-data-access' ), 'message_type' => 'error', 'message_is_dismissible' => false, ) ); $msg->box(); return false; } } } else { // TODO: how can I test the values of a manually created set? } return true; } } }