-
Posts
1,392 -
Joined
-
Last visited
-
Days Won
17
Everything posted by Juergen
-
Ok, I got it: Updating my Fieldtype file with this method solved my problem. I found this method inside the FieltypeText.module file. /** * Update a query to match the text with a fulltext index * * @param PageFinderDatabaseQuerySelect $query * @param string $table * @param string $subfield * @param string $operator * @param int|string $value * @return DatabaseQuerySelect * */ public function getMatchQuery($query, $table, $subfield, $operator, $value) { $ft = new DatabaseQuerySelectFulltext($query); $ft->match($table, $subfield, $operator, $value); return $query; }
-
Hello at all, I have created a new fieldtype with multiple fields (database columns) in it. More precisely it holds various company data (fe. company name, street, phone,...) - each in 1 database column. I want to make these values searchable in the site search, but it always shows me that the selector '~=' is not implement. It accepts '=' as a selector but not '~='. How can I implement this specific selector inside a fieldtype, so it does not throw me an error all the times, if I run a query with this selector. Thank you PS: My fieldtype class extends from Fieldtype
-
Thanks @LostKobrakai, but this was a misunderstanding. I wanted to prevent the usage of getUnformatted or page->of(false) or something like that method inside the template. I was looking for a possiblitiy to disable outputformatting inside the method itself, so I can use the API without adding a getUnformatted on the template base. But it doesnt matter, because it was a thinking mistake of mine. I dont need the unformatted value from the db - i need the value from the db in a specific format and therefore I am using a manipulation function to get the desired result. But it would be interesting if disabling the formatting inside a method itself is possible.
-
Hello @ all, Lets imagine I have a value stored in the database which I can output on the frontend with a simple API call like $page->myValue and this value will be manipulated with the formatValue() method before output on the frontend. So it was stored in the database like this: This is my value And after running through formatValue() method it will be: <p>This is my value.</p> So far so good. Now I have created a method inside my fieldtype/inputfield class which uses this value: public function myMethod() { $value = $this->myValue //value should be unformatted as dirctly stored in the database } Problem: myValue is always formatted because it runs through the formatValue method first - is there a way to get the "raw" data instead without setting ouputformatting to false inside the template if I call echo $page->myValue->myMethod(); I think it would not be possible because myMethod() is part of myValue, but maybe someone has an idea how it could work. Thanks in advance
-
2 new methods for Schema.org markup added: print_r($page->fieldname->getjsonLDTimes()); returns an array like this: Array ( [0] => Mo,Tu,We 08:00-12:00 [1] => Mo,Th 13:00-18:00 [2] => Th 08:00-11:00 ) Can be used to create the markup by yourself or echo $page->fieldname->renderjsonLDTimes(); returns a string like this: "Mo,Tu,We 08:00-12:00", "Mo,Th 13:00-18:00", "Th 08:00-11:00" You can use the second method in schema.org Local Business opening hours as followed: ..... "openingHours": [ "Mo,Th,Sa 11:00-14:30", "Mo,Th 17:00-21:30", "Fr,Sa 17:00-22:00" ], ..... Best regards
-
New feature added: I have updated the inputfield to support multilanguage timeformats on the frontend. You can set the timeformat of each language in the configuration of the inputfield in the backend (see screencast below). Supports strftime() and date() formats. Languageformat.mp4 Version was bumped from 1.0 to 1.1 on Github. Best regards Jürgen
-
Hello @ all I have 2 new methods added which take care of days with same times. It often happens that different days have exactly the same opening times. To prevent writing the same times over and over again, you can combine these days with this 2 new methods. 1) First new method to output a multidim. array print_r($page->fieldname->combinedDays()); You can use this array to create the markup by yourself. 2) Render method to output an unordered list of same opening times echo $page->fieldname->renderCombinedDays(); This method outputs a rendered string like this one: <ul class="uk-list"> <li>Mo, Fr: 08:00 - 16:00</li> <li>Tu, Th: 08:00 - 16:00, 18:00 - 20:00</li> <li>We: 16:00 - 23:05</li> <li>Sa, Su, Ho: closed</li> </ul> As you can see days with same times are combined now. Changes are added to Github now, so please download the files again if you want the latest version.? Best regards
-
Issue should be resolved and the file was updated on Github ?
-
Hi @bernhard Thanks for your feedback! I will check this and and try to find a solution. ? I have worked with this library in the past and it's really cool, but for the moment I have not planned to include a third party lib. The main purpose of this inputfield is to make entering of opening times simple for the user. Not really! Holidays are always hassle because they differ from country to country. For the moment you can enter only general opening times for all holidays. Exceptions can be really difficult and I guess there you will need to use Spatie to handle this.
-
Hello @ all ! Today I want to share another new inputfield with the community! It is called Fieldtype OpeningHours and it is designed to enter one or multiple times per day (especially for company opening times). I know that there is another great fieldtype in the repository (https://modules.processwire.com/modules/fieldtype-business-hours/), but I wanted to create my own with a different UI than the other one. Here is a screencast of what it looks like in action: OpeningHours.mp4 A lot of things going on behind the scenes and I dont want to write it all down here, because you can find the whole information on my Github account. https://github.com/juergenweb/FieldtypeOpeningHours Requirements: PHP >= 8.0 (because it uses union types, I have also tested it with new PHP 8.2) ProcessWire >=3.0.181 If you may find any bugs, have any ideas to improve this fieldtype please report it in my Github repository. Greetings from Austria and have a nice day! CHANGELOG: 21.7.20 Add new option to show (true) or hide (false) days with no opening hours on various methods (please be aware that setting options has been changed - it is recommended to deinstall old version and install this inputfield again) . Take a look at the READ.ME for further instructions. 1.1 Add multilang support for timeformat and add 2 additional Schema.org markup methods UPDATE: 09-06-2023: The module has been added to the module directory and can be downloaded from there after it has been published.
- 21 replies
-
- 18
-
-
Hello @ all, I have created an inputfield with a configuration field in the backend where you can set a time format for every language (see screenshot below). As you can see both language values (default and German) have the default value(%R), but I have set different values, which were correctly stored in the DB (see screenshot below): As you can see the values are '%R' and '%r'. I have created the configuration inputfield like this: /** @var InputfieldText $f */ $languages = $this->wire('languages'); $f = $this->wire('modules')->get('InputfieldText'); $f->attr('name+id', 'timeformat'); $f->label = $this->_('Timeformat on frontend'); $f->initValue = '%R';//default value $f->attr('value', $this->timeformat ? $this->timeformat : '%R'); $this->message($this->get('timesformat')); if($languages) { $f->useLanguages = true; foreach($languages as $language) { if($language->isDefault()) continue; $f->set("value$language", (string) $this->get("timeformat$language->id")); } } $f->inputType = 'text'; $f->description = $this->_('Please enter the time format that the times should appear on the frontend in strftime format.'); $f->notes = sprintf($this->_('For example shows the time as 08:00, as 08:00 AM. You can find more examples at %s.'), '<a href="https://www.php.net/manual/de/function.strftime.php">https://www.php.net/manual/de/function.strftime.php</a>'); $f->columnWidth = 100; The important part here is: if($languages) { $f->useLanguages = true; foreach($languages as $language) { if($language->isDefault()) continue; $f->set("value$language", (string) $this->get("timeformat$language->id")); } } I have borrowed the code from the DateTimeInputfield (https://github.com/processwire/processwire/blob/master/wire/modules/Inputfield/InputfieldDatetime/InputfieldDatetime.module), but the field values will be always populated with the default value ('%R'). Are I am missing something? Does anyone has experience with multilanguage fields and could help me out? Thanks in advance.
-
OK, I figured it out. I transformed the values of the inputfields inside the sleepValue function to a json array and now the values will be stored in the database. public function sleepValue(Page $page, Field $field, $value) { // throw error if value is not of the right type if (!$value instanceof OpeningHours) { throw new \Exception($this->_('Expecting an instance of OpeningHours')); } $content = json_encode($value->data['hours']); $sleepValue = ['hours' => $content]; return $sleepValue; } So the responsible lines are $content = json_encode($value->data['hours']); $sleepValue = ['hours' => $content]; The problem of the storage was that the column 'hours' was not defined in the sleepValue method. This was the important part because without it the system doesnt know where to store the value.
- 2 replies
-
- 2
-
-
- fieldtype
- inputfield
-
(and 1 more)
Tagged with:
-
OK, I am 1 step forward :-) Adding $this->value['hours'] = $time_values; to the processInput() method adds the values to the object Here is the complete code of this method: public function ___processInput(WireInputData $input): self { $name = $this->attr('name'); $value = $this->attr('value'); //input object includes always every input on the page, so lets filter out only inputs from this field //we need to do this, because the number of values is variable - so extract only values that starts with $name.'_' $nameAttributes = []; foreach($input as $key=>$value){ if(substr($key, 0, strlen($name.'_')) === $name.'_'){ $nameAttributes[$key] = $value; } } // loop through all inputfields and set the value (if changed or not) back $time_values = []; foreach($nameAttributes as $nameAttr => $value) { $time_values[$nameAttr] = $value; } //add it to the object $this->value['hours'] = $time_values; return $this; } Now the values are also reachable in sleepValue() method and the sanitizeValue() method. ProcessWire\OpeningHours Object ( [data] => Array ( [hours] => Array ( [openinghours_mo-0-start] => 09:00 [openinghours_mo-0-finish] => 13:00 [openinghours_mo-1-start] => 14:00 [openinghours_mo-1-finish] => 18:00 [openinghours_mo-2-start] => 21:00 [openinghours_mo-2-finish] => 23:00 [openinghours_tu-0-start] => 09:00 [openinghours_tu-0-finish] => 13:00 [openinghours_tu-1-start] => 14:00 [openinghours_tu-1-finish] => 18:00 [openinghours_we-0-start] => 09:00 [openinghours_we-0-finish] => 13:00 [openinghours_we-1-start] => 14:00 [openinghours_we-1-finish] => 18:00 [openinghours_th-0-start] => 09:00 [openinghours_th-0-finish] => 13:00 [openinghours_th-1-start] => 14:00 [openinghours_th-1-finish] => 18:00 [openinghours_fr-0-start] => 09:00 [openinghours_fr-0-finish] => 13:00 [openinghours_fr-1-start] => 14:00 [openinghours_fr-1-finish] => 18:00 [openinghours_sa-0-start] => [openinghours_sa-0-finish] => [openinghours_so-0-start] => [openinghours_so-0-finish] => [openinghours_ho-0-start] => [openinghours_ho-0-finish] => ) ) ) Nevertheless the value in the DB is NULL :-(
- 2 replies
-
- fieldtype
- inputfield
-
(and 1 more)
Tagged with:
-
Hello @ all, I am creating a new inputfield/fieldtype to store opening hours, but I am struggeling to save values from multiple dynamic created inputfields in 1 column of the database. Scenario: The user can enter one or more opening times per day in a UI. Fe: Monday open from 08:00 to 12:00 and from 14:00 to 17:00 Tuesday open from 08:00 to 12:00 and from 14:00 to 19:00 and so on Via a little JavaScript you can add as much opening times as you need per day - the additional inputfield will be created dynamically. After form submission all the values are in the POST array -> this works (see example below): ProcessWire\WireInputData Object ( [openinghours_mo-0-start] => 09:00 [openinghours_mo-0-finish] => 13:00 [openinghours_mo-1-start] => 14:00 [openinghours_mo-1-finish] => 18:00 [openinghours_mo-2-start] => 21:00 [openinghours_mo-2-finish] => 23:00 [openinghours_tu-0-start] => 09:00 [openinghours_tu-0-finish] => 13:00 [openinghours_tu-1-start] => 14:00 [openinghours_tu-1-finish] => 18:00 [openinghours_we-0-start] => 09:00 [openinghours_we-0-finish] => 13:00 [openinghours_we-1-start] => 14:00 [openinghours_we-1-finish] => 18:00 [openinghours_th-0-start] => 09:00 [openinghours_th-0-finish] => 13:00 [openinghours_th-1-start] => 14:00 [openinghours_th-1-finish] => 18:00 [openinghours_fr-0-start] => 09:00 [openinghours_fr-0-finish] => 13:00 [openinghours_fr-1-start] => 14:00 [openinghours_fr-1-finish] => 18:00 [openinghours_sa-0-start] => [openinghours_sa-0-finish] => [openinghours_so-0-start] => [openinghours_so-0-finish] => ) The property name is always the name attribute of the field ? . If the property is empty means closed on that day. Now I need to combine all those values into 1 array (or json array) and store it in the database in 1 column called 'hours' in my case (see screenshot below): In my ___processInput(WireInputData $input) method I have tried to make it work like this: public function ___processInput(WireInputData $input): self { $name = $this->attr('name'); $value = $this->attr('value'); //input object includes always every input on the page, so lets filter out only inputs from this field //we need to do this, because the number of values is variable - so extract only values that starts with $name.'_' $nameAttributes = []; foreach($input as $key=>$value){ if(substr($key, 0, strlen($name.'_')) === $name.'_'){ $nameAttributes[$key] = $value; } } // loop through all inputfields of this fieldtype $time_values = []; foreach($nameAttributes as $nameAttr => $value) { $time_values[$nameAttr] = $value; } } //save it in the database $input->set('hours', serialize($time_values)); return $this; } The only important part of this code is the last part with the serialize function. After saving it will create a record in the database, but the value is always NULL (default value) (see below). Checking $time_values returns all the values, but printing out "$this" shows me that the property "hours" inside the Openinghours object is empty (see below) - so the mistake must be there, but I dont know where?!?!?!? [title] => Home [openinghours] => ProcessWire\OpeningHours Object ( [data] => Array ( [hours] => ) ) If I check the sleepValue() method or the sanitizeValue() - they are also empty. So it seems that the values will not reach these methods. I havent found a clear documentation of whats going on behind the saving process of an inputfield. As far as I know the saving process starts with the form submission. The values are in the POST array and will be processed by the processInput() method. Before they will be saved in the database they will be sanitized by the sanitizeValue() mehtod and afterwards they will be prepared for storage in the sleepValue() method. The last step is the storage itself. Has someone an idea what is missing by storing values from multiple fields into 1 database column or has someone a working example of such a scenario on github to help me out. A clear explanation of the storage process will be also helpful. Thanks and best regards
- 2 replies
-
- fieldtype
- inputfield
-
(and 1 more)
Tagged with:
-
Hello @ all Today I want to share an inputfield/fieldtype to store 2 or 3 dimensions of an object. This fieldtype was inspired by the amazing fieldtype "Fieldtype Dimensions" from SOMA. This fieldtype was introduced in 2013 - so its time for a relaunch. This new fieldtype offers more possibilities than the old one. This inputfield/fieldtype let you enter max. 3 dimensions (width/height/depth) of an object (fe a product), but you can select if you want to display inputs for 2 or 3 dimensions. 2 dimension can be used fe for wallpapers or photos, 3 dimensions fe for furnitures or other objects. There are several configuration options for this fieldtype in the backend. set type (2 or 3 dimensional) set size unit as suffix after each inputfield (default is cm) set max number of decimals (default is 2) show/hide a hint to the user how much decimals are allowed If the number of decimals will be changed, the database schema for each dimension column will also change after saving the field in the backend. For example: If the schema for each dimension field in the DB is f.e. decimal(65,2) and you will set the number of decimals in the configuration to 3, then the schema in the DB will also change to decimal(65,3) after saving the inputfield. You can download this inputfield at https://github.com/juergenweb/FieldtypeObjectDimensions There you will find more detailed information and explanation too. If you find any bugs or you have an idea to improve it (also code improvements) please report it on Github. Have a nice day! UPDATE 14.06.23 / VERSION 1.2.2 I have re-written the complete fieldtype to be compatible with PHP 8.2 and refactored some of the methods and the database scheme. If you have downloaded the fieldtype before, please deinstall the old one and make a new install. I have added this fieldtype to the Processwire module directory. After it has been published, please download it from there.
- 2 replies
-
- 15
-
-
Hello @ all! I want to share a simple fieldtype and inputfield to store address data with you. I have created this inputfield for learning purposes and it has no fancy functionality. It is simply for storing address data such as street, number, postalcode and so on in one table. As an addition you can store latitude and longitude too, so you can use them in maps. Here is a screenshot of what it looks like: You can select which fields are mandatory and you can choose if the inputs for longitude and latitude should be displayed. These settings can be configured in the field configuration. If you find this inputfield useful you can download it at https://github.com/juergenweb/FieldtypeSimpleAddress There you will find a detailed explanation. If you have an idea of an usefull feature that can be added or you have detected a bug, please report it in my github account.
-
- 11
-
-
- inputfield
- address field
-
(and 1 more)
Tagged with:
-
I found a solution to keep multiple checkboxes checked after form submission. Here is the complete code of this multiple checkbox list field: // checkbox field to make specific fields required $f = $this->modules->get('InputfieldCheckboxes'); $f->label = _x('Required fields', 'simpleaddress'); $f->attr('name', 'input_required'); $options = [ 'street' => _x('Street', 'simpleaddress'), 'number' => _x('Number', 'simpleaddress'), 'postalcode' => _x('Postalcode', 'simpleaddress'), 'city' => _x('City', 'simpleaddress'), 'state' => _x('State', 'simpleaddress'), 'country' => _x('Country', 'simpleaddress'), ]; $values = (isset($this->hasField->data['input_required'])) ? $this->hasField->data['input_required'] : []; foreach($options as $value => $label) { $checked = (in_array($value,$values)) ? 'checked' : ''; $f->addOption($value, $label, ['checked' => $checked]); } $f->description = _x('If checked the input is required.', 'simpleaddress'); $inputfields->append($f); Lets take a closer look: $values = (isset($this->hasField->data['input_required'])) ? $this->hasField->data['input_required'] : []; This is how we get all checked checkboxes after form submission. "input_required" is the name attribute of my multiple checkbox field. If one or more checkboxes were checked, we get the values in an array, otherwise we will get an empty array. So $values could be an empty array or an array with values like ['street, postalcode']. To make the checkboxes checked after form submission we include a simple check inside the foreach loop. $checked = (in_array($value,$values)) ? 'checked' : ''; We check if the value from the foreach loop is in the array too. If yes, then add the checked attribute as third parameter to this checkbox input. $f->addOption($value, $label, ['checked' => $checked]); Thats all! Maybe someone has a nicer solution, please post it here. Best regards
-
Thanks for your help @Robin S Your code: Unfortunately $this->foo is always empty after form submission (independent if a checkbox was marked or not). Array ( [0] => ) By taking a look at the $this object you can see that you cannot reach the foo property via $this->foo, because foo is part of the field object. ProcessWire\InputfieldSimpleAddress Object ( [data] => Array ( [input_street] => [input_number] => [input_postalcode] => [input_city] => [input_state] => [input_country] => test [label] => Address [description] => [icon] => [notes] => [detail] => [head] => [required] => 0 [requiredIf] => [collapsed] => 0 [showIf] => [columnWidth] => [skipLabel] => [wrapClass] => [headerClass] => [contentClass] => [textFormat] => 4 [renderValueFlags] => 0 [prependMarkup] => [appendMarkup] => [hasFieldtype] => ProcessWire\FieldtypeSimpleAddress Object ( ) [hasField] => ProcessWire\Field Object ( [id] => 116 [name] => address [label] => Address [flags] => [type] => ProcessWire\FieldtypeSimpleAddress Object ( ) [data] => Array ( [label1021] => Adresse [collapsed] => 0 [foo] => Array ( [0] => red [1] => green [2] => blue ) ) ) [hasPage] => ProcessWire\Page Object ( [id] => 1 [name] => home [parent] => [status] => systemID [template] => home [numChildren] => 3 [title] => Home [data] => Array ( [title] => Home ) ) ) ) I have checked all 3 checkboxes and you get the values (red, green and blue) in the object as part of the data property (see code below): [data] => Array ( [label1021] => Adresse [collapsed] => 0 [foo] => Array ( [0] => red [1] => green [2] => blue ) ) Therefore you can get the values (array) only by using $this->hasField->data['foo'] instead of $this->foo My goal: I want to make multiple checkboxes stay checked after form submission if they were marked by an user. I havent found a way to achive this at the moment and this was the reason for this post.
-
Hello @ all, On a custom inputfield I want to use a multiple checkbox field (InputfieldCheckboxes) in the inputfield configuration. The user can select which fields of this inputfield are required. I have created these checkboxes as followed: As you can see, I am not using "InputfieldCheckbox" but "InputfieldCheckboxes" (the multi-checkbox version) $f = $this->modules->get('InputfieldCheckboxes'); $f->label = _x('Required fields', 'simpleaddress'); $options = [ 'street' => _x('Street', 'simpleaddress'), 'number' => _x('Number', 'simpleaddress'), 'postalcode' => _x('Postalcode', 'simpleaddress'), 'city' => _x('City', 'simpleaddress'), 'state' => _x('State', 'simpleaddress'), 'country' => _x('Country', 'simpleaddress'), ]; foreach($options as $value => $label) { $f->attr('name', 'input_required[]'); $checked = ($this->input_required == '1') ? 'checked' : '';//How to check if a checkbox was checked??????? $f->addOption($value, $label, ['checked' => $checked]); } $inputfields->append($f); Problem: I am struggeling to find out how to determine if a checkbox was checked or not . On a single checkbox field I can use something like this to set the checked attribute. $f->attr('checked', $this->myInputfield == '1' ? 'checked' : ''); How can I achive the same for a multiple checkbox field? I haven´t found a working example. Thanks in advance!
-
Put this code inside your ready.php which you will find inside your site/templates/ folder. If there is no such a file then create one (site/templates/ready.php)
-
@tires This is the hook to remove the unwanted generator meta tag. Best regards