mimpro Posted July 23, 2013 Share Posted July 23, 2013 Hi Presta buddies, I need help here in module development. i am going to put a dropdown list in the backoffice for user to select. Let say this list is an array ( 'none', 'solid', 'dashed', 'dotted') where i declared as $border_type. on the form, particularly for this dropdown parameter setting - this is where i stuck: array( 'type' => 'select', 'label' => $this->l('Border type:'), 'name' => 'border_type', 'required' => false, 'options' => array( 'query' => array ('none', 'solid', 'dashed', 'dotted'), 'id' => 'id', 'name' => 'name' ), ), ... it almost there, but i just get the dropdown list only for the first letter each.. would anybody here advise me how to make this succesfull? Link to comment Share on other sites More sharing options...
PascalVG Posted July 23, 2013 Share Posted July 23, 2013 Try this: add the red line to your array: array( 'type' => 'select', 'label' => $this->l('Border type:'), 'id' => 'my_unique_pattern_id_name', 'name' => 'border_type', 'required' => false, and add this line to the end of /<your admin folder>/themes/<your theme folder>/css/admin.css #my_unique_pattern_id_name {width: 400px;} (change 400px into any appropriate value for your screen) Hope this helps, pascal 1 Link to comment Share on other sites More sharing options...
mimpro Posted July 24, 2013 Author Share Posted July 24, 2013 (edited) Thanks PascalVG. i Tried and get the result like this Obviously this is not because of CSS property values, so I did check the actual generated code in 'Googel - inspect element' method and find that it did take the arrays's first letter only in to data... <div class="margin-form"> <select name="border_type" class="" id="border_type"> <option value=" n "> n </option> <option value="s"> s </option> <option value=" d "> d </option> <option value="d"> d </option> </select> </div> where if look back at the original php form (for the drop down list): array( 'type' => 'select', 'label' => $this->l('Border type:'), 'name' => 'border_type', 'required' => false, 'options' => array( 'query' => array ('none', 'solid', 'dashed', 'dotted'), 'id' => 'id', 'name' => 'name' ), ), I guess this is because some mistakes at the array itself. But i don't know how to deal with it. Edited July 24, 2013 by mimpro (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted July 24, 2013 Share Posted July 24, 2013 (edited) what if you try using an associative array? 'query' => array ('none'=>'none', 'solid'=>'solid', 'dashed'=>'dashed', 'dotted'=>'dotted') Edited July 24, 2013 by bellini13 (see edit history) 1 Link to comment Share on other sites More sharing options...
mimpro Posted July 24, 2013 Author Share Posted July 24, 2013 (edited) Dear Bellini13, Thank you for the suggestion. So I did the code, but there is still results the same. I think if somebody would like to get the full folder module, and check what's wrong there.. I appreciate it much and let me know your email so I'll send it. the module is not complicated. but I am not familiar enough with variable definitions, here are the declarations related to $border_type: custo.php class Custo extends Module ....(some typical codes) include_once $path.'/CustoClass.php'; // for extension. ...(some typical codes) public function install() { .....(some typical codes) $res = Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'custo` ( ....(some typical codes) `border_type` varchar(255) NOT NULL, //for the ps_custo .....(some typical codes) private function createExampleCusto($id_shop) { $custo = new CustoClass(); $custo->id_shop = (int)$id_shop; $custo->border_type = $border_type; // the assignment ...(some typical codes) private function initForm() ...(some typical codes) $this->fields_form[0]['form'] = array( 'tinymce' => true, 'legend' => array( 'title' => $this->displayName, 'image' => $this->_path.'logo.gif' ), ......(some typical codes for other variables and it works) array( 'type' => 'select', 'label' => $this->l('Border type:'), 'name' => 'border_type', //for the fieldset 'required' => false, 'options' => array( 'query' =>array ('none'=>'none', 'solid'=>'solid', 'dashed'=>'dashed', 'dotted'=>'dotted'), // the array 'id' => 'id_this', 'name' => 'border_type' ), ), CustoClass.php class CustoClass extends ObjectModel { .....(some typical codes) public $border_type; public static $definition = array( 'table' => 'custo', 'primary' => 'id_custo', 'multilang' => true, 'fields' => array( '..........(some typical codes) 'border_type' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 32) //please check here .... ......(some typical codes) public function copyFromPost() { /* Classical fields */ foreach ($_POST AS $key => $value) if (key_exists($key, $this) AND $key != 'id_'.$this->table) $this->{$key} = $value; Edited July 24, 2013 by mimpro (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted July 24, 2013 Share Posted July 24, 2013 Ah, first try I misunderstood the problem. I thought that it just didn't show the rest of the string. Obviously there's more going on here.... Just checking, but does this go wrong in other browsers? Seems that the form-creation procedure form the array info has problems here. The array looks ok to me, size 32 for the string looks ok. Somehow it cuts it off after 1 char. As the strings are shown on the user form, maybe try to use the Language-dependent form of the strings and see if that gives some clues: 'query' =>array ($this->l('none'), $this->l('solid'), $this->l('dashed'), $this->l('dotted')), // the array (Never tried it in an array. Hope it works...) 1 Link to comment Share on other sites More sharing options...
mimpro Posted July 24, 2013 Author Share Posted July 24, 2013 PascalVG, thanks for the idea. Yes i am suspecting the array creation is problem too. I'll try it out and results the same. The module is based on the original module of editorial from Prestashop. For the dropdowns, i refer to employee.php and AdminEmployee.php but so far they used array by pointing existing variables in SQL table. But what i done here is describe my own data in array. It is really confusing me hahaha.. ( well i thought if i could work on a module and follow their original coding concepts it would be a safe method to develop module) But i really need to have alternative solution if this doesn't work at all. Maybe i have to letgo the previous effort and move to some alternative idea/concepts : 1- make the module automatically install the values in a table (namely ps_custo_bordertype) for first installation and calls the value from the table (like Prestashop does).. but I have to get a guide how to move those values to that table and stays static. 2- Or try to use type radio button for the options. It seems that might works also but a bit spacious than a drop down if so many data in array. 3- Or forget about the form at all and code a normal html form in there.. well i'd like to try them all but if you think there is a better way to try, i appreciate it. Coz i am new to Prestashop and lack of knowledge and experiences yet. But the learning curve here is interesting! Link to comment Share on other sites More sharing options...
PascalVG Posted July 24, 2013 Share Posted July 24, 2013 About the table, there's a table 'ps_configuration' that can be used for your own values you want to store. you add a 'variable' to the table OR update a 'variable' in the table with code like this: Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', 4); (To create them, put them in your module install() function ) delete one from the table with: Configuration::deleteByName('BLOCK_CATEG_MAX_DEPTH'); (Put them in your module delete() function, to clean up when deleting the module) and get a value from the table like this: Configuration::get('BLOCK_CATEG_MAX_DEPTH'); For more info/example, see for example the file /modules/blockcategories/blockcategories.php So yo may try to use this and see if you can get the table values, add them to your array and see if that helps. pascal P.S. did other browsers give the same wrong result? 1 Link to comment Share on other sites More sharing options...
mimpro Posted July 24, 2013 Author Share Posted July 24, 2013 Pascal, the other browser also same. Anyway thank you for the guide.. i guess i'll try the method and share the result and hopefully this could work. Cheers! Link to comment Share on other sites More sharing options...
mimpro Posted July 26, 2013 Author Share Posted July 26, 2013 Well guys i found a simpler solution and i think it is good to share together. After several tries, for this case which i want to put my own array variables as dropdown list ( 'type' => 'select' ) in the private function initForm(). ... for the dropdown input details; array( 'type' => 'select', 'label' => $this->l('Border type:'), 'name' => 'border_type', 'required' => false, 'options' => array ( 'query' => array ( array( //--------------------------------- start first value 'id' => 'none', // ------------------------ 'id' => (write value of the variable) 'name' => $this->l('None') //---------- '$this->l(' put what you want it to display in dropdown list') ), //---------------------------------------- end of first value set.. repeat for all other values array( 'id' => 'solid', 'name' => $this->l('Solid') ), array( 'id' => 'dashed', 'name' => $this->l('Dashed') ), array( 'id' => 'dotted', 'name' => $this->l('Dotted') ), ), 'id' => 'id', 'name' => 'name' ), ), So, I put the explanation on the first value settings and just repeat the same for all values within the variable list. Purposely colored differently for easier to see the 'pattern'. I hope this would help others if they got the same problem here. This is solved now and moderator you may update this. But I encountered other things to solve now, and not related to this problem. I'll make a new post for that. Thank you for all replies. It keeps me alive here. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now