dostoyevski Posted January 5, 2023 Share Posted January 5, 2023 (edited) Hello, I am developing a prestashop module in which I need a calendar in which to select a date. It would be like this for a text field but with a calendar: array( 'col' => 3, 'type' => 'text', 'prefix' => '<i class="icon icon-envelope"></i>', 'desc' => $this->l('Introduce el nombre del usuario'), 'name' => 'MIMODULOMISMADB_ACCOUNT_USUARIO', 'label' => $this->l('Usuario'), ) Is it possible to add a calendar to the configuration page of the module? Edited January 9, 2023 by dostoyevski (see edit history) Link to comment Share on other sites More sharing options...
endriu107 Posted January 5, 2023 Share Posted January 5, 2023 Hi, check this: https://devdocs.prestashop-project.org/1.7/development/components/form/types-reference/date-picker/ Link to comment Share on other sites More sharing options...
dostoyevski Posted January 7, 2023 Author Share Posted January 7, 2023 On 1/5/2023 at 7:09 PM, endriu107 said: Hi, check this: https://devdocs.prestashop-project.org/1.7/development/components/form/types-reference/date-picker/ Hi, it's what I was looking for but I don't know how to use it. You have to create the CustomType class, but then I don't know how to add it to the getConfigForm() function. Link to comment Share on other sites More sharing options...
Piotr3qx Posted January 7, 2023 Share Posted January 7, 2023 This would work on a form using Symfony (e.g. category editing). When it comes to a typical form in a module, you have two ways. The first is to use JS to replace the text input with the date input (https://stackoverflow.com/questions/46754728/jquery-ui-date-picker-using-input-type-text, https://www.cssscript.com/ basic-date-picker-input-field/). The second way is to add your own .tpl file to the form, with hard-coded date input. Then in the postProcess() function you check if the input has a filled value and do what you want with it Link to comment Share on other sites More sharing options...
ps8modules Posted January 8, 2023 Share Posted January 8, 2023 Hi, sample form in the module: public function renderMyForm() { $values = array(); $this->fields_form = array(); $this->context->controller->addJqueryUI('ui.datepicker'); $defaultDate = date('Y-m-d'); if (!Configuration::get($this->name.'_my_date')){ $values['my_date'] = Tools::getValue('my_date', $defaultdate); } else { $values['my_date'] = Tools::getValue('my_date', Configuration::get($this->name.'_my_date')); } $fields_form[0] = array( 'form' => array( 'legend' => array( 'title' => $this->l('Settings'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'date', 'label' => $this->l('My date field'), 'name' => 'my_date', 'required' => true, ) ), 'submit' => array( 'title' => $this->l('Save settings'), 'class' => 'button btn btn-default pull-right', ) ), ); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $helper->identifier = $this->identifier; $helper->submit_action = 'Submit'.$this->name; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'fields_value' => $values, 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ); return $helper->generateForm(array($fields_form[0])); } And save date: public function postProcess() { if (Tools::isSubmit('Submit'.$this->name)) { if (Tools::getValue('my_date')){ Configuration::updateValue($this->name.'_my_date', Tools::getValue('my_date')); Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&module_name='.$this->name); } } } 1 Link to comment Share on other sites More sharing options...
dostoyevski Posted January 9, 2023 Author Share Posted January 9, 2023 perfect! It worked ok, thank you! 1 Link to comment Share on other sites More sharing options...
ps8modules Posted January 9, 2023 Share Posted January 9, 2023 I gladly helped 😉 You can like by clicking on the gray heart below my posts. 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