Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 12-29-2014, 02:47 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 113,421
Abronsyth is on a distinguished road
Default Drop Down List to Use Item Messed Up

Okay, this is weird.

The drop down list, when you go through to use an item, is showing me my adoptables' ID number (1), not name (Snowball), and when I got to use it, I end up with this error:
"Adoptable ID SnowBall does not exist or does not belong to the owner specified..."
As though the name (Snowball) is being selected when the ID (1) should be. It is almost like the two have changed positions.

Here's what I mean:


So, if someone could help just let me know which files you'd need to see. Here's my class_dropdownlist.php, just in case:
PHP Code:
<?php

use Resource\Native\String;
use 
Resource\Collection\Collective;
use 
Resource\Collection\LinkedList;
use 
Resource\Collection\LinkedHashMap;

/**
 * The DropdownList Class, extends from abstract GUIContainer class.
 * It specifies a standard single-item dropdown list.
 * @category Resource
 * @package GUI
 * @author Hall of Famer 
 * @copyright Mysidia Adoptables Script
 * @link http://www.mysidiaadoptables.com
 * @since 1.3.3
 * @todo Not much at this point.
 *
 */

class DropdownList extends GUIContainer{
    
    
/**
     * The autofocus property, checks if the input component is autofocused.
     * @access protected
     * @var Boolean
    */
    
protected $autofocus FALSE;
    
    
/**
     * The disabled property, checks if the input component is disabled.
     * @access protected
     * @var Boolean
    */
    
protected $disabled FALSE;
    
    
/**
     * Constructor of SelectList Class, which assigns basic property to this list
     * @param String  $name
     * @param ArrayList  $components
     * @param String  $identity
     * @param Event  $event
     * @access public
     * @return Void
     */
    
public function __construct($name ""$components ""$identity ""$event ""){
        if(!empty(
$name)){
            
$this->setName($name);
            
$this->setID($name);
        }
        if(!empty(
$identity)) $this->select($identity);
        if(!empty(
$event)) $this->setEvent($event);
        
        
parent::__construct($components);
        
$this->renderer = new ListRenderer($this);        
    }
    
    
/**
     * The isAutofocus method, getter method for property $autofocus.    
     * @access public
     * @return Boolean
     */
    
public function isAutofocus(){
        return 
$this->autofocus;    
    }

    
/**
     * The setAutofocus method, setter method for property $autofocus.
     * @param Boolean  $autofocus      
     * @access public
     * @return Void
     */
    
public function setAutofocus($autofocus TRUE){
        
$this->autofocus $autofocus;
        
$this->setAttributes("Autofocus");
    }    
    
    
/**
     * The isDisabled method, getter method for property $disabled.    
     * @access public
     * @return Boolean
     */
    
public function isDisabled(){
        return 
$this->disabled
    }

    
/**
     * The setDisabled method, setter method for property $disabled.
     * @param Boolean  $disabled       
     * @access public
     * @return Void
     */
    
public function setDisabled($disabled TRUE){
        
$this->disabled $disabled;
        
$this->setAttributes("Disabled");
    }

    
/**
     * The add method, sets an Option Object to a specific index.
     * @param Option|OptGroup  $option
     * @param int  $index     
     * @access public
     * @return Void
     */    
    
public function add($option$index = -1){
        if(!(
$option instanceof Option) and !($option instanceof OptGroup)) throw new GUIException("Cannot add a non-option type component to dropdown list.");
        
parent::add($option$index);            
    }
    
    
/**
     * The select method, determines which option in this list should be set selected.
     * @param String  $identity   
     * @access public
     * @return Void
     */
    
public function select($identity){
        foreach(
$this->components as $components){
            if(
$components->getValue() == $identity$components->setSelected(TRUE);
        }        
    }
    
    
/**
     * The fill method, fill in this dropdownlist with options from database starting at a given index.
     * To use it, you need PDO or MySQLi to fetch all rows with one or two properties to serve as collection list or map.
     * @param Collective $collection
     * @param String  $identity
     * @param Int  $index     
     * @access public
     * @return Void
     */
    
public function fill(Collective $collection$identity ""$index = -1){
        if(
$index != -1$this->currentIndex $index;        
        if(
$collection instanceof LinkedList$this->fillList($collection$identity$index);
        elseif(
$collection instanceof LinkedHashMap$this->fillMap($collection$identity$index);
        else throw new 
GUIException("Cannot fill option objects inside this dropdownlist");
    }

    
/**
     * The fillList method, fill in this dropdownlist with elements from a LinkedList.
     * @param LinkedList  $list
     * @param String  $identity
     * @param Int  $index     
     * @access protected
     * @return Void
     */
    
protected function fillList(LinkedList $list$identity ""$index = -1){
        
$iterator $list->iterator();
        while(
$iterator->hasNext()){
            
$field = (string)$iterator->next();
             
$option = new Option($field$field);
            if(
$option->getValue() == $identity$option->setSelected(TRUE);
            
$this->add($option$index);
            if(
$index != -1$index++;           
        }        
    }

    
/**
     * The fillList method, fill in this dropdownlist with entries from a LinkedHashMap.
     * @param LinkedHashMap  $map
     * @param String  $identity
     * @param Int  $index     
     * @access protected
     * @return Void
     */
    
protected function fillMap(LinkedHashMap $map$identity ""$index = -1){
        
$iterator $map->iterator();
        while(
$iterator->hasNext()){
            
$field $iterator->next();
             
$option = new Option((string)$field->getKey(), (string)$field->getValue()); 
            if(
$option->getValue() == $identity$option->setSelected(TRUE);
            
$this->add($option$index);
            if(
$index != -1$index++;           
        }        
    }

    
/**
     * Magic method __toString for DropdownList class, it reveals that the object is a dropdown list.
     * @access public
     * @return String
     */
    
public function __toString(){
        return new 
String("This is an instance of Mysidia DropDownList class.");
    }    
}    
?>
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #2  
Old 12-29-2014, 03:37 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,376
IntoRain is on a distinguished road
Default

On mine it actually shows the name instead of the id. Does this happen with all dropdown lists? Can you post your inventoryview.php and inventory.php files? (just the uses() function for example)
__________________


asp.net stole my soul.
Reply With Quote
  #3  
Old 12-29-2014, 06:05 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 113,421
Abronsyth is on a distinguished road
Default

It's driving me nuts, haha XD ((Took my 6 months to learn html and css, taken me 3+ years and still haven't learned php...someday I'll be able to solve these issues. Soooome day.)).

Inventoryview.php:
PHP Code:
    public function uses(){
        
$mysidia Registry::get("mysidia");
        
$document $this->document;    
        if(
$mysidia->input->post("aid")){
            
$message = (string)$this->getField("message");
            
$document->setTitle($mysidia->lang->global_action_complete);
            
$document->addLangvar($message);
            return;        
        }
        
        
$petMap $this->getField("petMap");
        
$document->setTitle($mysidia->lang->select_title);
        
$document->addLangvar($mysidia->lang->select);        
        
$chooseFrom = new Form("chooseform""uses""post");
        
        
$adoptable = new DropdownList("aid");
        
$adoptable->add(new Option("None Selected""none"));
        if(
$petMap->size() > 0){
            
$iterator $petMap->iterator();
            while(
$iterator->hasNext()){
                
$adopt $iterator->nextEntry();
                
$adoptable->add(new Option($adopt->getValue(), $adopt->getKey()));
            }
        }        
        
$chooseFrom->add($adoptable);
        
        
$chooseFrom->add(new PasswordField("hidden""itemname"$mysidia->input->post("itemname")));
        
$chooseFrom->add(new PasswordField("hidden""validation""valid"));
        
$chooseFrom->add(new Button("Choose this Adopt""submit""submit"));
        
$document->add($chooseFrom);
    } 
Inventory.php:
PHP Code:
    public function uses(){
        
$mysidia Registry::get("mysidia");
        
$document $mysidia->frame->getDocument();
        
$item = new PrivateItem($mysidia->input->post("itemname"), $mysidia->user->username);   
        if(
$item->iid == 0) throw new ItemException("use_none");
        
        if(
$mysidia->input->post("aid")){
            if(!
$item->checktarget($mysidia->input->post("aid")) or $mysidia->input->post("validation") != "valid"){
                throw new 
ItemException("use_fail");
            }
            elseif(!
$item->randomchance()){
                
$item->remove();
                throw new 
ItemException("use_effect");
            }
            else{ 
                
$message $item->apply($mysidia->input->post("aid")); 
                
$this->setField("message"$message);
            }    
            return;            
        }

        
$stmt $mysidia->db->select("owned_adoptables", array("aid""name"), "owner = '{$mysidia->user->username}'");
        
$map $mysidia->db->fetchMap($stmt);
        
$this->setField("petMap"$map);
    } 
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #4  
Old 12-29-2014, 06:54 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,376
IntoRain is on a distinguished road
Default

Quote:
Originally Posted by Abronsyth View Post
It's driving me nuts, haha XD ((Took my 6 months to learn html and css, taken me 3+ years and still haven't learned php...someday I'll be able to solve these issues. Soooome day.)).
Haha php is a whole programming language, it's normal to take longer to learn! You gotta go step by step

In this part:

Inventoryview.php
PHP Code:
$adoptable->add(new Option($adopt->getValue(), $adopt->getKey())); 
Do you have any idea why the value and the key are inverted? It's basically creating an option with the text shown to the user as $adopt->getValue() (the adoptable's id) and the text sent to the server as $adopt->getKey() (the adoptable's name).
Doing this should fix it:

PHP Code:
//to show the id
$adoptable->add(new Option($adopt->getValue(), $adopt->getValue()));

//or to show the name instead
$adoptable->add(new Option($adopt->getKey(), $adopt->getValue())); 
But I don't know why it was inverted in the first place, so I don't know if there's any other system associated with that that might break...
__________________


asp.net stole my soul.

Last edited by IntoRain; 12-29-2014 at 06:58 PM.
Reply With Quote
  #5  
Old 12-30-2014, 10:37 AM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 113,421
Abronsyth is on a distinguished road
Default

Alright, thank you!

Huh, not sure why it was inverted.
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mys v1.3.4 Item Shop Mod(s): NPC + Item Display + Tooltips Kyttias Mys v1.3.x Mods 55 06-19-2020 11:21 AM
Creating a drop down list within FORM to SHOW FounderSim Questions and Supports 6 09-27-2014 04:39 PM
Too many drop down bars? Infernette Questions and Supports 4 01-29-2013 04:01 PM
HTML Drop-down Menu Knyfe Tutorials and Tips 2 02-17-2011 04:03 PM


All times are GMT -5. The time now is 07:58 AM.

Currently Active Users: 9738 (0 members and 9738 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636